#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];
}
int 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, int 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];
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |