#pragma GCC optimize("O3")
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
int a[MAXN], n;
int ok(ll b, int len) {
ll cur = 0;
for (int i = 0; i < len; i++)
cur += abs((ll) a[i] - a[(len - 1) / 2]);
if (cur <= b)
return 1;
for (int i = len; i < n; i++) {
cur += (ll) (a[(len-1)/2+i-len+1]-a[(len-1)/2+i-len]) * (ll) ((len-1)/2+1);
cur -= (ll) (a[(len-1)/2+i-len+1]-a[(len-1)/2+i-len]) * (ll) (len-((len-1)/2+1));
cur -= abs((ll) a[i - len] - a[(len-1)/2+i-len+1]);
cur += abs((ll) a[i] - a[(len-1)/2+i-len+1]);
if (cur <= b)
return 1;
}
return 0;
}
int besthub(int r, int l, int x[], ll b) {
for (int i = 0; i < r; i++)
a[i] = x[i];
n = r;
int lo = 1, hi = r, ans = 1;
while (lo <= hi) {
int m = (lo + hi) / 2;
if (ok(b, m))
lo = m + 1, ans = m;
else
hi = m - 1;
}
return ans;
}
/*int main()
{
int ans = besthub(5, 20, {1, 2, 10, 12, 14}, 6);
pri(ans);
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
640 KB |
Output is correct |
2 |
Correct |
7 ms |
640 KB |
Output is correct |
3 |
Correct |
21 ms |
2168 KB |
Output is correct |
4 |
Correct |
24 ms |
2208 KB |
Output is correct |
5 |
Correct |
14 ms |
1024 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
18 ms |
1920 KB |
Output is correct |
8 |
Correct |
22 ms |
1892 KB |
Output is correct |
9 |
Correct |
15 ms |
1056 KB |
Output is correct |
10 |
Correct |
12 ms |
1024 KB |
Output is correct |
11 |
Correct |
29 ms |
2196 KB |
Output is correct |
12 |
Correct |
27 ms |
2176 KB |
Output is correct |
13 |
Correct |
13 ms |
1152 KB |
Output is correct |
14 |
Correct |
21 ms |
1156 KB |
Output is correct |
15 |
Correct |
22 ms |
1792 KB |
Output is correct |
16 |
Correct |
19 ms |
1644 KB |
Output is correct |
17 |
Correct |
30 ms |
2040 KB |
Output is correct |
18 |
Correct |
29 ms |
1968 KB |
Output is correct |
19 |
Correct |
24 ms |
2048 KB |
Output is correct |
20 |
Correct |
33 ms |
2060 KB |
Output is correct |