0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 08:45:25 +00:00
OI-codes/Luogu/P1873/P1873.cpp

34 lines
606 B
C++
Raw Normal View History

2020-12-30 13:40:20 +00:00
#include <bits/stdc++.h>
using namespace std;
long long n, m, l, r, ans, a[1000005];
bool check(long long x) {
long long t = 0;
for (long long i = 1; i <= n; i++) {
if (a[i] > x) {
t += a[i] - x;
}
}
return t >= m;
}
int main() {
cin >> n >> m;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
r = max(r, a[i]);
}
while (l <= r) {
long long mid = l + r >> 1;
if (check(mid)) {
l = (ans = mid) + 1;
2021-11-19 09:01:13 +00:00
} else {
2020-12-30 13:40:20 +00:00
r = mid - 1;
}
}
cout << ans << endl;
return 0;
}