Using long long int while calculating wooden cutting to avoid wrong answer during submission

programming
Tags: #<Tag:0x00007f242433c698>

#1

Comment body gobool isRequire(int height,vector &A, int B){
long long int wc=0;
for(auto a:A){
if(a>height) wc+=(a-height);
}
return wc>=B;
}

int Solution::solve(vector &A, int B) {
int low=0,high= *max_element(A.begin(),A.end());
int ans=-1;
while(low<=high){
int mid=(low+high)/2;
if(isRequire(mid,A,B)) low=mid+1;
else high=mid-1;
}
return low-1;
}es here.