Why is this code not working?


#1

int Solution::nchoc(int K, vector &A) {
int N=A.size();
make_heap(A.begin(),A.end());
int sum=0;
for(int i=K;i>0;i–)
{
int m=A.front();
sum+=A.front();
A.pop_back();
make_heap(A.begin(),A.end());
A.push_back(floor(m/2));
make_heap(A.begin(),A.end());
}
while(sum<0)sum+=(pow(10,9)+7);
return sum;
}


#2

Use long long for sum… It will pass…