#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int n; ll arr[N], sum[N];
ll get(ll l, ll r, ll M) {
ll ret = 0;
if(arr[r] <= M) return (r - l + 1) * M - sum[r] + sum[l-1];
if(M <= arr[l]) return sum[r] - sum[l-1] - (r - l + 1) * M;
int p = lower_bound(arr,arr+n,M) - arr;
return M * (p - l) - sum[p-1] + sum[l-1] + sum[r] - sum[p-1] - M * (r - p + 1);
}
int besthub(int R, int L, int X[], ll B) {
n = R;
for(int i = 1; i <= n; i++) arr[i] = X[i-1];
for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + arr[i];
int lo = 1, hi = n, ans = 1;
while(lo <= hi) {
int mid = (lo + hi) >> 1;
int can = 0;
for(int i = 1; i + mid - 1 <= n; i++) {
int med;
if(mid & 1) med = arr[i + mid/2];
else med = (arr[i + mid/2] + arr[i + mid/2 + 1]) / 2;
for(ll M = med - 10; M <= med + 10; M++)
if(get(i, i + mid - 1, M) <= B) { can = 1; break; }
if(can) break;
}
if(can) ans = mid, lo = mid + 1;
else hi = mid - 1;
} return ans;
}
Compilation message
ricehub.cpp: In function 'll get(ll, ll, ll)':
ricehub.cpp:11:5: warning: unused variable 'ret' [-Wunused-variable]
ll ret = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
472 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
516 KB |
Output is correct |
4 |
Correct |
2 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
2 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
560 KB |
Output is correct |
8 |
Correct |
2 ms |
560 KB |
Output is correct |
9 |
Correct |
2 ms |
560 KB |
Output is correct |
10 |
Correct |
2 ms |
560 KB |
Output is correct |
11 |
Correct |
2 ms |
560 KB |
Output is correct |
12 |
Correct |
2 ms |
560 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
636 KB |
Output is correct |
18 |
Correct |
2 ms |
636 KB |
Output is correct |
19 |
Correct |
2 ms |
636 KB |
Output is correct |
20 |
Correct |
2 ms |
636 KB |
Output is correct |
21 |
Correct |
2 ms |
636 KB |
Output is correct |
22 |
Correct |
3 ms |
636 KB |
Output is correct |
23 |
Correct |
2 ms |
636 KB |
Output is correct |
24 |
Correct |
2 ms |
636 KB |
Output is correct |
25 |
Correct |
2 ms |
636 KB |
Output is correct |
26 |
Correct |
2 ms |
636 KB |
Output is correct |
27 |
Correct |
3 ms |
636 KB |
Output is correct |
28 |
Correct |
3 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
672 KB |
Output is correct |
2 |
Correct |
2 ms |
672 KB |
Output is correct |
3 |
Correct |
2 ms |
672 KB |
Output is correct |
4 |
Correct |
2 ms |
672 KB |
Output is correct |
5 |
Correct |
2 ms |
672 KB |
Output is correct |
6 |
Correct |
2 ms |
672 KB |
Output is correct |
7 |
Correct |
3 ms |
676 KB |
Output is correct |
8 |
Correct |
3 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
676 KB |
Output is correct |
10 |
Correct |
2 ms |
676 KB |
Output is correct |
11 |
Correct |
4 ms |
676 KB |
Output is correct |
12 |
Correct |
4 ms |
676 KB |
Output is correct |
13 |
Correct |
2 ms |
676 KB |
Output is correct |
14 |
Correct |
2 ms |
676 KB |
Output is correct |
15 |
Correct |
3 ms |
676 KB |
Output is correct |
16 |
Correct |
3 ms |
784 KB |
Output is correct |
17 |
Correct |
2 ms |
784 KB |
Output is correct |
18 |
Correct |
2 ms |
784 KB |
Output is correct |
19 |
Correct |
2 ms |
784 KB |
Output is correct |
20 |
Correct |
2 ms |
784 KB |
Output is correct |
21 |
Correct |
12 ms |
784 KB |
Output is correct |
22 |
Correct |
12 ms |
784 KB |
Output is correct |
23 |
Correct |
2 ms |
784 KB |
Output is correct |
24 |
Correct |
2 ms |
784 KB |
Output is correct |
25 |
Correct |
2 ms |
784 KB |
Output is correct |
26 |
Correct |
2 ms |
784 KB |
Output is correct |
27 |
Correct |
12 ms |
784 KB |
Output is correct |
28 |
Correct |
12 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
1224 KB |
Output is correct |
2 |
Correct |
130 ms |
1224 KB |
Output is correct |
3 |
Correct |
15 ms |
2632 KB |
Output is correct |
4 |
Correct |
15 ms |
2632 KB |
Output is correct |
5 |
Correct |
239 ms |
2632 KB |
Output is correct |
6 |
Correct |
241 ms |
2632 KB |
Output is correct |
7 |
Correct |
13 ms |
2632 KB |
Output is correct |
8 |
Correct |
14 ms |
2632 KB |
Output is correct |
9 |
Correct |
216 ms |
2632 KB |
Output is correct |
10 |
Correct |
249 ms |
2632 KB |
Output is correct |
11 |
Correct |
16 ms |
2632 KB |
Output is correct |
12 |
Correct |
17 ms |
2632 KB |
Output is correct |
13 |
Correct |
317 ms |
2632 KB |
Output is correct |
14 |
Correct |
309 ms |
2632 KB |
Output is correct |
15 |
Correct |
13 ms |
2632 KB |
Output is correct |
16 |
Correct |
13 ms |
2632 KB |
Output is correct |
17 |
Correct |
16 ms |
3400 KB |
Output is correct |
18 |
Correct |
15 ms |
4392 KB |
Output is correct |
19 |
Correct |
16 ms |
5484 KB |
Output is correct |
20 |
Correct |
16 ms |
6484 KB |
Output is correct |