#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll psum(int i, int j, vector<ll> &prefix) {
if (i > j) {
return 0;
}
if (i == 0) {
return prefix[j];
}
return prefix[j] - prefix[i - 1];
}
int besthub(int N, int L, int X[], ll B) {
vector<ll> prefix(N + 1);
prefix[0] = X[0];
for (int i = 1; i <= N; i++) {
prefix[i] = X[i] + prefix[i - 1];
}
int ans = 0;
for (int i = 0, j = 0; i < N; i++) {
while (j + 1 <= i) {
int mid = (i + j) / 2;
ll x = X[mid] * (mid - j + 1) - psum(j, mid, prefix);
if (mid + 1 <= i) {
x += psum(mid + 1, i, prefix) - X[mid] * (i - mid);
}
if (x <= B) {
break;
}
j++;
}
ans = max(ans, i - j + 1);
}
return ans;
}
// int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// int R, L;
// cin >> R >> L;
// int X[R];
// for (ll i = 0; i < R; i++) {
// cin >> X[i];
// }
// ll B;
// cin >> B;
// cout << besthub(R, L, X, B) << "\n";
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
344 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 |
1 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 |
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 |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
504 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
600 KB |
Output is correct |
10 |
Correct |
1 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 |
0 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 |
348 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 |
500 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
9 ms |
3420 KB |
Output is correct |
4 |
Correct |
9 ms |
3440 KB |
Output is correct |
5 |
Correct |
5 ms |
2908 KB |
Output is correct |
6 |
Correct |
4 ms |
2836 KB |
Output is correct |
7 |
Correct |
8 ms |
3420 KB |
Output is correct |
8 |
Correct |
9 ms |
3420 KB |
Output is correct |
9 |
Correct |
4 ms |
2908 KB |
Output is correct |
10 |
Correct |
4 ms |
2908 KB |
Output is correct |
11 |
Correct |
9 ms |
3420 KB |
Output is correct |
12 |
Correct |
13 ms |
3420 KB |
Output is correct |
13 |
Correct |
5 ms |
2908 KB |
Output is correct |
14 |
Correct |
5 ms |
2908 KB |
Output is correct |
15 |
Correct |
7 ms |
3164 KB |
Output is correct |
16 |
Correct |
7 ms |
3160 KB |
Output is correct |
17 |
Correct |
9 ms |
3164 KB |
Output is correct |
18 |
Correct |
8 ms |
3164 KB |
Output is correct |
19 |
Correct |
10 ms |
3184 KB |
Output is correct |
20 |
Correct |
9 ms |
3420 KB |
Output is correct |