#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
int n;
ll budget;
vector<ll> psum;
bool check(int rice, int a[]) {
ll middle = (rice-1) / 2;
ll right = (rice)/2 + middle;
ll minb = 3e15;
for (int i = 0; i <= n - rice; i++) {
ll b = abs((right - middle) * (a[i+middle]) - (psum[i+right+1] - psum[i+middle+1]));
//cout << "b1: " << b << endl;
b += abs((middle) * a[i+middle] - (psum[i+middle] - psum[i]));
minb = min(b, minb);
//cout << "b: " << b << endl;
}
//cout << "minb: " << minb << endl;
if (minb <= budget) return true;
return false;
}
int besthub(int ri, int maxcoor, int a[], ll b) {
n = ri;
budget = b;
psum.resize(n+1);
for (int i = 1; i <= n; i++) {
psum[i] = a[i-1] + psum[i-1];
}
// for (int i = 0; i < n; i++) cout << psum[i] << " ";
// cout << endl;
// for (int i = 0; i < n; i++) cout << ssum[i] << " ";
// cout << endl;
ll l = 1, r = (ll)n;
while (l < r) {
ll mid = (l + r + 1) / 2;
//cout << "mid: " << mid << endl;
if (check(mid, a)) {
l = mid;
}
else {
r = mid - 1;
}
}
return l;
}
// signed main() {
// int r, l; ll 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
380 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
544 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
9 ms |
3284 KB |
Output is correct |
4 |
Correct |
9 ms |
3416 KB |
Output is correct |
5 |
Correct |
6 ms |
2908 KB |
Output is correct |
6 |
Correct |
6 ms |
3068 KB |
Output is correct |
7 |
Correct |
9 ms |
3420 KB |
Output is correct |
8 |
Correct |
9 ms |
3344 KB |
Output is correct |
9 |
Correct |
6 ms |
2908 KB |
Output is correct |
10 |
Correct |
5 ms |
2908 KB |
Output is correct |
11 |
Correct |
10 ms |
3420 KB |
Output is correct |
12 |
Correct |
9 ms |
3420 KB |
Output is correct |
13 |
Correct |
6 ms |
2908 KB |
Output is correct |
14 |
Correct |
6 ms |
2908 KB |
Output is correct |
15 |
Correct |
8 ms |
3268 KB |
Output is correct |
16 |
Correct |
10 ms |
3164 KB |
Output is correct |
17 |
Correct |
9 ms |
3164 KB |
Output is correct |
18 |
Correct |
8 ms |
3164 KB |
Output is correct |
19 |
Correct |
9 ms |
3416 KB |
Output is correct |
20 |
Correct |
9 ms |
3420 KB |
Output is correct |