/**
* author: tourist
* created:
**/
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int besthub(int n, int len, int a[], long long b) {
vector<long long> p(n + 1);
for (int i = 0; i < n; i++) {
p[i + 1] = a[i];
p[i + 1] += p[i];
}
auto rsum = [&](int l, int r) -> int64_t {
return p[r] - p[l - 1];
};
int ans = 1;
for (int i = 1; i <= n; i++) {
int low = i + 1, high = n, idx = -1;
while (low <= high) {
int mid = (low + high) >> 1, med = (i + mid) >> 1;
long long cost = int64_t(med - i + 1) * int64_t(a[med]) - rsum(i, med) + rsum(med + 1, mid) - int64_t(mid - med) * int64_t(a[med]);
if (cost <= b) {
idx = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
ans = max(ans, idx - i + 1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
452 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
352 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
600 KB |
Output is correct |
3 |
Correct |
14 ms |
4444 KB |
Output is correct |
4 |
Correct |
14 ms |
4444 KB |
Output is correct |
5 |
Correct |
7 ms |
3416 KB |
Output is correct |
6 |
Correct |
7 ms |
3164 KB |
Output is correct |
7 |
Correct |
13 ms |
4188 KB |
Output is correct |
8 |
Correct |
16 ms |
4184 KB |
Output is correct |
9 |
Correct |
8 ms |
3164 KB |
Output is correct |
10 |
Correct |
8 ms |
3164 KB |
Output is correct |
11 |
Correct |
14 ms |
4444 KB |
Output is correct |
12 |
Correct |
14 ms |
4460 KB |
Output is correct |
13 |
Correct |
7 ms |
3420 KB |
Output is correct |
14 |
Correct |
7 ms |
3420 KB |
Output is correct |
15 |
Correct |
11 ms |
3940 KB |
Output is correct |
16 |
Correct |
11 ms |
3932 KB |
Output is correct |
17 |
Correct |
13 ms |
4196 KB |
Output is correct |
18 |
Correct |
13 ms |
4328 KB |
Output is correct |
19 |
Correct |
14 ms |
4196 KB |
Output is correct |
20 |
Correct |
14 ms |
4324 KB |
Output is correct |