https://www.acmicpc.net/problem/2805
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int m=s.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=s.nextInt();
}
Arrays.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;
}
System.out.print(max);
}
}