#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
int besthub(int R, int L, int X[], long long B) {
int ans=0;
long long cost=0;
for (int i=0; i<R; i++){
cost=0;
int pans=0, pos;
for (int j=0; j<R; j++){
if (X[j] == X[i]){
pos=j;
break;
}
}
int pl=pos-1, pr=pos;
while(1){
if (pl<0 && pr>=R) break;
else if (pr>=R){
ll tl = X[i] - X[pl];
if (cost + tl <= B){
cost+=tl;
pans++;
pl--;
}else break;
}else if (pl<0){
ll tr = X[pr] - X[i];
if (cost + tr <= B){
cost+=tr;
pans++;
pr++;
}else break;
}else{
ll tr=X[pr] - X[i], tl=X[i] - X[pl];
if (tr<tl){
if (cost + tr <= B){
cost+=tr;
pans++;
pr++;
}else break;
}else{
if (cost + tl <= B){
cost+=tl;
pans++;
pl--;
}else break;
}
}
}
ans=max(ans, pans);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
7 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
8 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
384 KB |
Output is correct |
19 |
Correct |
10 ms |
384 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
14 ms |
384 KB |
Output is correct |
22 |
Correct |
19 ms |
384 KB |
Output is correct |
23 |
Correct |
89 ms |
384 KB |
Output is correct |
24 |
Correct |
76 ms |
384 KB |
Output is correct |
25 |
Correct |
125 ms |
384 KB |
Output is correct |
26 |
Correct |
132 ms |
384 KB |
Output is correct |
27 |
Correct |
43 ms |
384 KB |
Output is correct |
28 |
Correct |
48 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
444 KB |
Output is correct |
2 |
Correct |
113 ms |
512 KB |
Output is correct |
3 |
Execution timed out |
1093 ms |
1152 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |