#include <bits/stdc++.h>
#include "ricehub.h"
#define lc id<<1
#define rc id<<1^1
#define nmax 100008
using namespace std;
int n, mx, ans = 0, a[nmax];
long long k;
struct segtree{
long long seg[nmax << 2];
void build(int id = 1, int l = 1, int r = n){
if (l == r){
seg[id] = a[l];
return;
}
int mid = (l + r) >> 1;
build(lc, l, mid);
build(rc, mid + 1, r);
seg[id] = seg[lc] - seg[rc];
}
long long get(int u, int v, int id = 1, int l = 1, int r = n){
if (r < u || l > v)
return 0;
if (u <= l && r <= v)
return seg[id];
int mid = (l + r) >> 1;
return get(u, v, lc, l, mid) + get(u, v, rc, mid + 1, r);
}
}tree;
long long cost(int l, int r){
if (l == r)
return 0;
int mid = (l + r) >> 1;
return 1LL * a[mid] * (mid - l + 1) - tree.get(l, mid) + tree.get(mid + 1, r) - 1LL * a[mid] * (r - mid);
}
int besthub(int R, int L, int X[], long long B){
n = R;
mx = L;
k = B;
for (int i = 1; i <= n; i++)
a[i] = X[i - 1];
tree.build();
for (int i = 1, j = 1; i <= n; i++){
while (cost(j, i) > B)
j++;
ans = max(ans, i - j + 1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |