WoodCutting is really easy if you sort it!


#1
int Solution::solve(vector<int> &A, int B) {
sort(A.begin(), A.end());
int n=A.size();
int diff=0, i, dum=0;
for(i=0; i<n; i++){
    diff += (A[n-1-i] - A[n-2-i])*(i+1);
    if(diff>=B) {
        break;
    }
    dum=diff;
}
return A[n-i-1] - ceil((B-dum)/float(i+1));

}