#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector <ll> sp;
vector <int> x;
inline pair <ll, int> check(int dst, int R, int cord, int pos) {
int l = 0, r = 0;
for(int step = 1 << 16; step; step >>= 1) {
if(l + step <= R && cord - dst > x[l + step]) {
l += step;
}
if(r + step <= R && cord + dst >= x[r + step]) {
r += step;
}
}
pair <ll, int> ans;
ans.first = 1LL * (pos - l) * x[pos] - (sp[pos] - sp[l]) + (sp[r] - sp[pos]) - 1LL * (r - pos) * x[pos];
ans.second = r - l;
/*if(pos == 1) {
cerr << dst << " " << l + 1 << " " << r << " " << ans.first << " " << ans.second << "\n";
}*/
return ans;
}
int besthub(int R, int L, int X[], long long B) {
x.resize(R + 1), sp.resize(R + 1);
for(int i = 1; i <= R; i++) {
x[i] = X[i - 1];
sp[i] = sp[i - 1] + x[i];
}
ll ans = 0;
for(int i = 1; i <= R; i++) {
int dst = 0;
for(int step = 1 << 30; step; step >>= 1) {
if(check(dst + step, R, x[i], i).first < B) {
dst += step;
}
}
auto cur = check(dst, R, x[i], i);
dst++;
ans = max(ans, cur.second + (B - cur.first) / dst);
//cerr << i << " " << cur.first << " " << cur.second << " " << dst << "\n";
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
356 KB |
Output is correct |
21 |
Correct |
3 ms |
252 KB |
Output is correct |
22 |
Correct |
3 ms |
256 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
256 KB |
Output is correct |
27 |
Correct |
3 ms |
256 KB |
Output is correct |
28 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
768 KB |
Output is correct |
2 |
Correct |
48 ms |
768 KB |
Output is correct |
3 |
Incorrect |
270 ms |
3004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |