#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 += (X[p] * (p-l+1) - (pre[p] - pre[l-1]));
dis += (pre[r] - pre[p]) - 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 < L; 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 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1004 KB |
Execution killed with signal 7 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |