#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
ll Abs(ll x) {
if (x < 0)return -x;
return x;
}
ll have;
ll n;
ll a[101010];
ll tr(ll x) {
ll now = have;
ll cl = 1;
for (ll i = 1; i <= n; i++) {
if (Abs(a[i] - x) < Abs(a[cl] - x))
cl = i;
}
ll ans = 0;
if (Abs(a[cl] - x) <= now) {
now -= Abs(a[cl] - x);
ans++;
ll l = cl - 1, r = cl + 1;
while (true) {
if (l < 1 && r > n)break;
if (l < 1 && r <= n && Abs(a[r] - x) <= now) {
now -= Abs(a[r] - x);
r++;ans++;continue;
}
if (r > n && l >= 1 && Abs(a[l] - x) <= now) {
now -= Abs(a[l] - x);
l--;ans++;continue;
}
if (l >= 1 && r <= n && Abs(a[l] - x) <= Abs(a[r] - x) && Abs(a[l] - x) <= now) {
now -= Abs(a[l] - x);
l--;ans++;continue;
}
if (l >= 1 && r <= n && Abs(a[l] - x) >= Abs(a[r] - x) && Abs(a[r] - x) <= now) {
now -= Abs(a[r] - x);
r++;ans++;continue;
}
break;
}
}
// cout << x << " --- " << ans << " " << cnt << endl;
return ans;
}
ll ans = 0;
int besthub(int R, int L, int X[], long long B) {
n = R;
for (ll i = 0; i < R; i++)
a[i + 1] = X[i];
have = B;
int l = 0, r = n + 1;
while (l + 1000 < r) {
int m1 = l + (r - l) / 3;
int m2 = r - (r - l) / 3;
if (tr(a[m1]) < tr(a[m2]))
l = m1;
else
r = m2;
}
for (ll i = l; i <= r; i++) {
ans = max(ans, tr(a[i]));
}
return ans;
}
/**
5 20 6
1
2
10
12
14
3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
204 KB |
Output is correct |
24 |
Correct |
2 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
3 ms |
204 KB |
Output is correct |
13 |
Correct |
4 ms |
204 KB |
Output is correct |
14 |
Correct |
4 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
312 KB |
Output is correct |
17 |
Correct |
6 ms |
204 KB |
Output is correct |
18 |
Correct |
6 ms |
312 KB |
Output is correct |
19 |
Correct |
6 ms |
204 KB |
Output is correct |
20 |
Correct |
6 ms |
320 KB |
Output is correct |
21 |
Correct |
15 ms |
368 KB |
Output is correct |
22 |
Correct |
15 ms |
332 KB |
Output is correct |
23 |
Correct |
23 ms |
364 KB |
Output is correct |
24 |
Correct |
27 ms |
344 KB |
Output is correct |
25 |
Correct |
49 ms |
332 KB |
Output is correct |
26 |
Correct |
49 ms |
444 KB |
Output is correct |
27 |
Correct |
23 ms |
360 KB |
Output is correct |
28 |
Correct |
27 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
528 KB |
Output is correct |
2 |
Correct |
44 ms |
460 KB |
Output is correct |
3 |
Correct |
345 ms |
1456 KB |
Output is correct |
4 |
Correct |
400 ms |
1428 KB |
Output is correct |
5 |
Correct |
121 ms |
872 KB |
Output is correct |
6 |
Correct |
119 ms |
844 KB |
Output is correct |
7 |
Correct |
338 ms |
1468 KB |
Output is correct |
8 |
Correct |
423 ms |
1456 KB |
Output is correct |
9 |
Correct |
138 ms |
844 KB |
Output is correct |
10 |
Correct |
140 ms |
948 KB |
Output is correct |
11 |
Correct |
349 ms |
1356 KB |
Output is correct |
12 |
Correct |
479 ms |
1452 KB |
Output is correct |
13 |
Incorrect |
133 ms |
964 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |