#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 69;
ll seg[4*maxn];
ll a[maxn];
int n;
void Build(int l, int r, int pos){
if (l==r){
seg[pos] = a[l];
return;
}
int mid = (l+r)/2;
Build(l, mid, pos*2);
Build(mid + 1, r, pos*2 + 1);
seg[pos] = seg[pos * 2] + seg[pos * 2 + 1];
}
ll Query(int l, int r, int pos, int ql, int qr){
if (l>r) return 0;
if (l>=ql && r<=qr)
return seg[pos];
else if (l>qr || ql>r) return 0;
int mid = (l+r)/2;
return Query(l, mid, pos*2, ql, qr) + Query(mid + 1, r, pos*2 + 1, ql, qr);
}
bool check(int l, int r, ll B){
int mid = (l+r)/2;
int pos = a[mid];
ll val = (mid - l + 1) * pos - Query(1, n, 1, l, mid);
val += Query(1, n, 1, mid, r) - (r - mid + 1) * pos;
return val <= B;
}
int besthub(int R, int L, int X[], long long B)
{
n = R;
for (int i=1; i<=n; i++){
a[i] = X[i-1];
}
Build(1, n, 1);
int ans = 0;
int r = 0;
for (int l=1; l<=n; l++){
while (r!=n && check(l, r+1, B))
r++;
ans = max(ans, r-l+1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 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 |
212 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 |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
260 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
5 ms |
468 KB |
Output is correct |
22 |
Correct |
4 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1068 KB |
Output is correct |
2 |
Correct |
13 ms |
1072 KB |
Output is correct |
3 |
Correct |
39 ms |
3412 KB |
Output is correct |
4 |
Correct |
40 ms |
3540 KB |
Output is correct |
5 |
Correct |
42 ms |
2204 KB |
Output is correct |
6 |
Correct |
31 ms |
2260 KB |
Output is correct |
7 |
Correct |
38 ms |
4308 KB |
Output is correct |
8 |
Correct |
45 ms |
4292 KB |
Output is correct |
9 |
Correct |
38 ms |
2132 KB |
Output is correct |
10 |
Correct |
36 ms |
2132 KB |
Output is correct |
11 |
Correct |
39 ms |
4588 KB |
Output is correct |
12 |
Correct |
39 ms |
4580 KB |
Output is correct |
13 |
Correct |
35 ms |
2276 KB |
Output is correct |
14 |
Correct |
46 ms |
2268 KB |
Output is correct |
15 |
Correct |
29 ms |
4008 KB |
Output is correct |
16 |
Correct |
28 ms |
4020 KB |
Output is correct |
17 |
Correct |
35 ms |
4308 KB |
Output is correct |
18 |
Correct |
36 ms |
4260 KB |
Output is correct |
19 |
Correct |
37 ms |
4428 KB |
Output is correct |
20 |
Correct |
37 ms |
4428 KB |
Output is correct |