#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
int n, budget;
vector<int> psum;
vector<int> ssum;
bool check(int rice) {
int middle = (rice-1) / 2;
int right = middle+(rice)/2;
int minb = 1e9;
for (int i = 0; i <= n - rice; i++) {
int b = psum[i+right] - psum[i+middle] + ssum[i] - ssum[i+middle];
minb = min(b, minb);
}
//cout << "minb: " << minb << endl;
if (minb <= budget) return true;
return false;
}
int besthub(int r, int maxcoor, int a[], ll b) {
n = r;
budget = b;
int diff[n-1];
for (int i = 0; i < n-1; i++) {
diff[i] = a[i+1] - a[i];
}
psum.resize(n, 0);
ssum.resize(n, 0);
for (int i = 1; i < n; i++) {
psum[i] = diff[i-1] + psum[i-1];
}
for (int i = n-2; i >= 0; i--) {
ssum[i] = diff[i] + ssum[i+1];
}
int l = 1;
while (l < r) {
int mid = (l + r + 1) / 2;
//cout << "mid: " << mid << endl;
if (check(mid)) {
l = mid;
}
else {
r = mid - 1;
}
}
return l;
}
// signed main() {
// int r, l, b; cin >> r >> l >> b;
// int x[r];
// for (int i = 0; i < r; i++) cin >> x[i];
// cout << besthub(r, l, x, b) << endl;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |