#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int besthub(int R, int L, int X[], long long B) {
vector<ll> lft;
vector<ll> rgt;
int best = 0;
int n = R;
for (int i = n - 1; i > 0; --i) {
rgt.push_back(X[i]);
}
for (int i = 0; i < n; ++i) {
ll leftm = B;
int cur = 1;
int li = lft.size() - 1;
int ri = rgt.size() - 1;
while (true) {
ll leftd = li >= 0 ? abs(lft[li] - X[i]) : 1e18;
ll rightd = ri >= 0 ? abs(rgt[ri] - X[i]) : 1e18;
if (min(leftd, rightd) > leftm) break;
cur++;
if (leftd < rightd) {
leftm -= leftd;
li--;
} else {
leftm -= rightd;
ri--;
}
}
best = max(best, cur);
lft.push_back(X[i]);
rgt.pop_back();
}
return best;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
320 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
212 KB |
Output is correct |
26 |
Correct |
2 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
5 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
212 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
20 |
Correct |
7 ms |
212 KB |
Output is correct |
21 |
Correct |
5 ms |
468 KB |
Output is correct |
22 |
Correct |
8 ms |
468 KB |
Output is correct |
23 |
Correct |
80 ms |
428 KB |
Output is correct |
24 |
Correct |
67 ms |
456 KB |
Output is correct |
25 |
Correct |
159 ms |
412 KB |
Output is correct |
26 |
Correct |
157 ms |
416 KB |
Output is correct |
27 |
Correct |
44 ms |
468 KB |
Output is correct |
28 |
Correct |
42 ms |
424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
848 KB |
Output is correct |
2 |
Correct |
8 ms |
848 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
1868 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |