#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
vector <ll> arr;
ll RO(ll budget, ll idx) {
vector <int> pq;
for (ll x : arr) pq.push_back(abs(x-arr[idx]));
ll paks = 1, suma = 0, lb = idx-1, ub = idx+1;
while (lb >= 0 || ub < n) {
if (lb >= 0 && ub < n && pq[lb] <= pq[ub]) {
if (suma + pq[lb] <= budget) suma += pq[lb], lb--, paks++;
else break;
}
else if (lb >= 0 && ub < n && pq[lb] > pq[ub]) {
if (suma + pq[ub] <= budget) suma += pq[ub], ub++, paks++;
else break;
}
else if (lb >= 0) {
if (suma + pq[lb] <= budget) suma += pq[lb], lb--, paks++;
else break;
}
else if (ub < n) {
if (suma + pq[ub] <= budget) suma += pq[ub], ub++, paks++;
else break;
}
else {}
}
return paks;
}
int besthub(int R, int L, int X[], ll B) {
for (ll i=0; i<R; i++) arr.push_back((ll)X[i]);
n = R;
ll maxi = 0;
for (ll i=0; i<R; i++) {
maxi = max(maxi, RO(B, i));
}
return maxi;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 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 |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
288 KB |
Output is correct |
4 |
Correct |
7 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 |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
6 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 |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
7 ms |
384 KB |
Output is correct |
14 |
Correct |
7 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 |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
7 ms |
384 KB |
Output is correct |
19 |
Correct |
10 ms |
384 KB |
Output is correct |
20 |
Correct |
9 ms |
384 KB |
Output is correct |
21 |
Correct |
114 ms |
512 KB |
Output is correct |
22 |
Correct |
104 ms |
640 KB |
Output is correct |
23 |
Correct |
160 ms |
512 KB |
Output is correct |
24 |
Correct |
152 ms |
512 KB |
Output is correct |
25 |
Correct |
202 ms |
632 KB |
Output is correct |
26 |
Correct |
201 ms |
632 KB |
Output is correct |
27 |
Correct |
129 ms |
512 KB |
Output is correct |
28 |
Correct |
128 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1040 ms |
1212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |