이번 문제는 이분탐색을 통해 해결하였다.
#include <iostream>
#include <algorithm>
#define MAX 1000001
using namespace std;
int n;
long long k;
long long x[MAX];
long long cnt=0;
long long result=0;
void Input(){
cin>>n>>k;
for(int i=0; i<n; i++){
cin>>x[i];
}
sort(x, x+n);
}
void BinarySearch(){
long long front = x[0];
long long back = x[0]+k;
while(front<=back){
long long mid = (front+back)/2;
cnt=0;
for(int i=0; i<n; i++){
if(mid>x[i]){
cnt+=(mid-x[i]);
}
else break;
}
if(cnt>k){
back=mid-1;
}
else{
result=mid;
front=mid+1;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
Input();
BinarySearch();
cout<<result<<endl;
return 0;
}