https://www.acmicpc.net/problem/2805
using System;
class Program
{
static void Main() {
string[] s=Console.ReadLine().Split(' ');
int n=int.Parse(s[0]);
int m=int.Parse(s[1]);
int[] arr=new int[n];
string[] s1=Console.ReadLine().Split(' ');
for(int i=0;i<n;i++){
arr[i]=int.Parse(s1[i]);
}
Array.Sort(arr);
long max=arr[n-1];
long min=1;
long mid=0;
while(min<=max){
long num=0;
mid=(min+max)/2;
for(int i=0;i<n;i++){
if(arr[i]>=mid) num+=arr[i]-mid;
}
if(num>=m) min=mid+1;
else max=mid-1;
}
Console.Write(max);
}
}