Simple and easy cpp solution


#1

int Solution::solve(vector &A, int B) {
sort(A.begin(),A.end());
int count=0,max;
// int max=A[A.size()-1];
// cout<<max;
max=A[A.size()-1];
while(count<B)
{
count=0;
//cout<<max;
for(int i=0;i<A.size();i++)
{
//count+=(A[i]-max)>0?max-A[i]:0;
if((A[i]-max)>0)
count+=(A[i]-max);
else
count+=0;
}
max–;
}
return max+1;
}