Solution Cpp very easy and stupid


#1

int find(vectorA, int mid)
{
int res=0;
for(auto i:A)
{
if(i>mid) res+=(i-mid);
}
return res;
}

int Solution::solve(vector &A, int B) {
sort(A.begin(),A.end());
int high=A[A.size()-1];
for(int i=high;i>=high-B;i–)
{
if(find(A,i)>=B) return i;
}
}