fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int n, m;
  5. ll a[200005];
  6. bool check(ll x){
  7.  
  8. ll cnt = 0;
  9. for(int i = 1; i <= n; i++){
  10. if(x >= a[i]) cnt += x - a[i];
  11. }
  12. if(cnt <= m) return true;
  13. else return false;
  14. }
  15. int main()
  16. {
  17. ios_base::sync_with_stdio(0);
  18. cout.tie(0);cin.tie(0);
  19. cin >> n >> m;
  20. for(int i = 1; i <= n; i++) cin >> a[i];
  21.  
  22. ll l = 0, r = 1e18, mid, ans;
  23. while(l <= r){
  24. mid = (l + r) / 2;
  25. if(check(mid) == true){
  26. l = mid + 1;
  27. ans = mid;
  28. }
  29. else{
  30. r = mid - 1;
  31. }
  32. }
  33.  
  34. cout << ans;
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
1000000000000000000