101二分答案
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define fi first 4 #define se second 5 #define go continue 6 #define woc puts(""); 7 #define int long long 8 #define PII pair<int, int> 9 #define sf(x) scanf("%lld",&x) 10 #define ytz int _; sf(_); while(_--) 11 #define fory(i,a,b) for(int i = a; i <= b; ++i) 12 #define forl(i,a,b) for(int i = a; i >= b; --i) 13 #define debug(a) cout << #a << " = " << a <<endl; 14 const int N = 1e5 + 10; 15 int n, k, a[N]; 16 bool check(int x) 17 { 18 int cnt = k; 19 fory(i, 1, n) 20 { 21 if(a[i] < x) cnt -= (x - a[i]); 22 if(cnt < 0) return 0; 23 } 24 return 1; 25 } 26 signed main() 27 { 28 sf(n),sf(k); 29 fory(i, 1, n) sf(a[i]); 30 sort(a + 1, a + 1 + n); 31 32 33 int l = 1, r = 1e18; 34 while(l < r) 35 { 36 // cout << l << " " << r << endl; 37 int mid = (l + r + 1) >> 1; 38 39 //debug(mid); 40 if(check(mid)) 41 { 42 // debug(mid); 43 l = mid; 44 } 45 else r = mid - 1; 46 } 47 printf("%lld\n", l); 48 return 0; 49 }