fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. bool f(ll mid ,vector<ll>&a,ll x){
  9. ll check=0;
  10. for(int i=0;i<a.size() && a[i]<mid;i++)
  11. check+=mid-a[i];
  12. return check<=x;
  13. }
  14.  
  15. void solve() {
  16. ll n,x;
  17. cin >> n >> x;
  18. vector<ll> a(n);
  19. sort(a.begin(),a.end());
  20. for(ll i=0;i<n;i++) cin >> a[i];
  21. ll l=1,r=1e9+7;
  22. ll ans = 1;
  23. while(l<=r){
  24. ll m = (l+r)/2;
  25. if(f(m,a,x)){
  26. ans=m;
  27. l=m+1;
  28. }
  29. else r=m-1;
  30. }
  31. cout << ans << '\n';
  32. }
  33.  
  34. int main(){
  35. ios::sync_with_stdio(false);
  36. cin.tie(nullptr);
  37.  
  38. int t;
  39. cin >> t;
  40. while (t--) solve();
  41.  
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5272KB
stdin
5
7 9
3 1 2 4 6 2 5
3 10
1 1 1
4 1
1 4 3 4
6 1984
2 6 5 9 1 8
1 1000000000
1
stdout
4
4
2
335
1000000001