#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 1e5 + 5;
ll N, L, B;
int x[MX];
bool can(int k) {
if(k & 1) {
ll cur = 0;
for(int i = 0; i < k / 2; i++) cur -= x[i];
for(int i = k / 2 + 1; i < k; i++) cur += x[i];
if(cur <= B) return 1;
for(int i = k; i < N; i++) {
// add i
cur += x[i];
// remove i - k
cur += x[i - k];
// add
cur -= x[i - k + k / 2];
// remove
cur -= x[i - k + k / 2 + 1];
if(cur <= B) return 1;
}
return 0;
} else {
ll cur = 0;
for(int i = 0; i < k / 2; i++) cur -= x[i];
for(int i = k / 2; i < k; i++) cur += x[i];
if(cur <= B) return 1;
for(int i = k; i < N; i++) {
// add i
cur += x[i];
// remove i - k
cur += x[i - k];
// add
cur -= x[i - k + k / 2];
// remove
cur -= x[i - k + k / 2];
if(cur <= B) return 1;
}
return 0;
}
}
int besthub(int _N, int _L, int _x[], ll _B) {
N = _N, L = _L, B = _B;
for(int i = 0; i < N; i++) x[i] = _x[i];
int l = 1, r = N, res = 0;
while(l <= r) {
int mid = (l + r) >> 1;
if(can(mid)) {
l = mid + 1, res = mid;
} else {
r = mid - 1;
}
}
return res;
}
// int a[100];
// int main() {
// ios_base::sync_with_stdio(0); cin.tie(0);
// int N, L, B;
// cin >> N >> L >> B;
// for(int i = 0; i < N; i++) cin >> a[i];
// cout << besthub(N, L, a, B) << '\n';
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Correct |
1 ms |
304 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
572 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
12 ms |
2128 KB |
Output is correct |
4 |
Correct |
14 ms |
2124 KB |
Output is correct |
5 |
Correct |
5 ms |
960 KB |
Output is correct |
6 |
Correct |
5 ms |
980 KB |
Output is correct |
7 |
Correct |
9 ms |
1748 KB |
Output is correct |
8 |
Correct |
10 ms |
1748 KB |
Output is correct |
9 |
Correct |
5 ms |
980 KB |
Output is correct |
10 |
Correct |
5 ms |
980 KB |
Output is correct |
11 |
Correct |
11 ms |
2136 KB |
Output is correct |
12 |
Correct |
11 ms |
2124 KB |
Output is correct |
13 |
Correct |
5 ms |
980 KB |
Output is correct |
14 |
Correct |
6 ms |
988 KB |
Output is correct |
15 |
Correct |
8 ms |
1576 KB |
Output is correct |
16 |
Correct |
8 ms |
1588 KB |
Output is correct |
17 |
Correct |
9 ms |
1836 KB |
Output is correct |
18 |
Correct |
9 ms |
1932 KB |
Output is correct |
19 |
Correct |
10 ms |
1996 KB |
Output is correct |
20 |
Correct |
12 ms |
2044 KB |
Output is correct |