▲ 1 r/codeforces
Doubt in Today's Contest
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
sort(v.begin(),v.end());
if(v[n-1] == 1){
cout<<0<<endl;
continue;
}
//n == 1 && n == 2 cases
if(n == 1){
if(v[0] < 3){
cout<<0<<endl;
continue;
}
}
if(v[n-1] != 1 && v[n-2] == 1){
cout<<v[n-1] + v[n-1]/2<<endl;
continue;
}
long long single = 0;
long long extras = 0;
long long ans = 0;
for(int i=0;i<n;i++){
if(v[i] == 1){
single++;
}
else{
ans = ans + v[i];
extras += (v[i]/2) - 1;
}
}
ans = ans + min(single,extras);
cout<<ans<<endl;
}
}
can someone pls explain why my code doesnt work?? today's C btw
u/CtrlAltDestiny — 4 days ago