https://www.acmicpc.net/problem/2512
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=s.nextInt();
}
int max=s.nextInt();
Arrays.sort(arr);
int left=0;
int right=arr[n-1];
while(left<=right){
int mid=(left+right)/2;
int now=0;
for(int num : arr){
if(mid>=num) now+=num;
else now+=mid;
}
if(now>max) right=mid-1;
else left=mid+1;
}
System.out.print(right);
}
}