mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-25 05:32:00 +00:00
P1873 砍树
R44441314
This commit is contained in:
parent
b605576bc0
commit
5d0e00416e
35
problem/P1873/P1873.cpp
Normal file
35
problem/P1873/P1873.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#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;
|
||||
}
|
||||
else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user