1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 const int N = 1000010; 6 typedef long long ll; 7 int tree[N], n; 8 ll m; 9 bool check(int h){ 10 ll sum = 0; 11 for(int i = 1; i <= n; i ++) 12 if(tree[i] >= h) 13 sum += tree[i] - h; 14 if(sum >= m) return true; 15 else return false; 16 } 17 int main(){ 18 scanf("%d%lld", &n, &m); 19 for(int i = 1; i <= n; i ++) scanf("%d", &tree[i]); 20 sort(tree + 1, tree + 1 + n); 21 int l = 1, r = 1e9; 22 int ans = 0; 23 while(l < r){ 24 int mid = l + r + 1 >> 1; 25 if(check(mid)) l = mid; 26 else r = mid - 1; 27 } 28 cout << l << endl; 29 30 return 0; 31 }