#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 200000;
vector <long long> pre;
long long cal(int l, int r, int X[]) {
int p = l + r >> 1;
long long dis = 0;
dis += ((long long) X[p] * (p-l+1) - (pre[p] - pre[l-1]));
dis += (pre[r] - pre[p]) - (long long) X[p] * (r-p);
return dis;
}
int besthub(int R, int L, int X[], long long B) {
pre.resize(R);
pre[0] = X[0];
for (int i = 1; i < R; i++)
pre[i] = pre[i-1] + X[i];
int l = 1, r = R, mid;
while (l < r) {
mid = (l + r + 1) >> 1;
bool flag = 0;
for (int i = 0; i+mid-1 < R; i++) {
if (cal(i, i+mid-1, X) <= B) flag = 1;
}
if (flag) l = mid;
else r = mid-1;
}
return l;
}
Compilation message
ricehub.cpp: In function 'long long int cal(int, int, int*)':
ricehub.cpp:13:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int p = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 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 |
2 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 |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
2 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 |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
492 KB |
Output is correct |
2 |
Correct |
4 ms |
492 KB |
Output is correct |
3 |
Correct |
15 ms |
1516 KB |
Output is correct |
4 |
Correct |
16 ms |
1516 KB |
Output is correct |
5 |
Correct |
11 ms |
1016 KB |
Output is correct |
6 |
Correct |
12 ms |
876 KB |
Output is correct |
7 |
Correct |
22 ms |
1516 KB |
Output is correct |
8 |
Correct |
21 ms |
1516 KB |
Output is correct |
9 |
Correct |
14 ms |
1024 KB |
Output is correct |
10 |
Correct |
14 ms |
876 KB |
Output is correct |
11 |
Correct |
15 ms |
1516 KB |
Output is correct |
12 |
Correct |
25 ms |
1516 KB |
Output is correct |
13 |
Correct |
10 ms |
876 KB |
Output is correct |
14 |
Correct |
10 ms |
1260 KB |
Output is correct |
15 |
Correct |
19 ms |
1972 KB |
Output is correct |
16 |
Correct |
15 ms |
2028 KB |
Output is correct |
17 |
Correct |
18 ms |
2284 KB |
Output is correct |
18 |
Correct |
21 ms |
2284 KB |
Output is correct |
19 |
Correct |
15 ms |
2412 KB |
Output is correct |
20 |
Correct |
27 ms |
2412 KB |
Output is correct |