Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cin >> n >> m;
- FOR(i, 1, n) cin >> a[i];
- int res = -1;
- int l = 0;
- int r = 1000000000;
- while (l <= r) {
- int mid = (l+r)/2;
- int tmp = m;
- bool tt = true;
- FOR(i, 1, n)
- if (a[i] < mid) {
- tmp = tmp - (mid-a[i]);
- if (tmp < 0) {
- tt = false;
- break;
- }
- }
- if (tt) {
- res = mid;
- l = mid + 1;
- } else r = mid - 1;
- }
- cout << res;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement