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