#include <bits/stdc++.h>
//#include "ricehub.h"
using namespace std;
vector<int> v;
vector<long long> sum;
long long cost (int l, int r) {
l++;r++;
int mij = (l + r) / 2;
return (1ll * v[mij] * (mij - l + 1) - (sum[mij] - sum[l - 1]) + (sum[r] - sum[mij - 1]) - 1ll * (r - mij + 1) * v[mij]);
}
int besthub (int n, int l, int x[], long long b) {
sum.resize(n + 2);
v.resize(n + 2);
for (int i = 0; i < n; i++) {
sum[i + 1] = sum[i] + x[i] ;
v[i + 1] = x[i];
}
int sol = 0;
for (int i = 0; i < n; i++) {
int st = i, dr = n - 1, ans = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
if (cost(i, mij) <= b) {
ans = mij;
st = mij + 1;
}
else
dr = mij - 1;
}
sol = max(sol, ans - i + 1);
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
640 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
620 KB |
Output is correct |
2 |
Correct |
5 ms |
748 KB |
Output is correct |
3 |
Correct |
25 ms |
2924 KB |
Output is correct |
4 |
Correct |
25 ms |
2924 KB |
Output is correct |
5 |
Correct |
12 ms |
1516 KB |
Output is correct |
6 |
Correct |
12 ms |
1516 KB |
Output is correct |
7 |
Correct |
23 ms |
2668 KB |
Output is correct |
8 |
Correct |
25 ms |
2668 KB |
Output is correct |
9 |
Correct |
11 ms |
1388 KB |
Output is correct |
10 |
Correct |
11 ms |
1388 KB |
Output is correct |
11 |
Correct |
25 ms |
2924 KB |
Output is correct |
12 |
Correct |
25 ms |
2924 KB |
Output is correct |
13 |
Correct |
12 ms |
1536 KB |
Output is correct |
14 |
Correct |
12 ms |
1516 KB |
Output is correct |
15 |
Correct |
19 ms |
2412 KB |
Output is correct |
16 |
Correct |
18 ms |
2284 KB |
Output is correct |
17 |
Correct |
22 ms |
2668 KB |
Output is correct |
18 |
Correct |
22 ms |
2668 KB |
Output is correct |
19 |
Correct |
30 ms |
2796 KB |
Output is correct |
20 |
Correct |
28 ms |
2796 KB |
Output is correct |