fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. freopen("MINING.INP","r",stdin);
  8. freopen("MINING.OUT","w",stdout);
  9. int n;
  10. ll S;
  11. cin >> n >> S;
  12. vector<ll> a(n);
  13. for (int i = 0; i < n; i++) cin >> a[i];
  14. ll l = 0, r = *maxe(a.begin(), a.end());
  15. ll ans = 0;
  16. while (l <= r) {
  17. ll mid = (l + r) / 2;
  18. ll sum = 0;
  19. for (ll x : a) {
  20. if (x > mid) sum += x - mid;
  21. }
  22. if (sum >= S) {
  23. ans = mid;
  24. l = mid + 1;
  25. } else {
  26. r = mid - 1;
  27. }
  28. }
  29. cout << ans;
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5284KB
stdin
4 3
5 3 7 8
stdout
6