#include <bits/stdc++.h>
#include "ricehub.h"
#define DIM 200010
using namespace std;
long long sp[DIM];
int v[DIM];
long long get_sum (int x, int y){
if (x > y)
return 0;
return sp[y] - sp[x-1];
}
int verif (int val, int n, long long b){
for (int i=1;i<=n-val+1;i++){
int st = i, dr = i + val-1;
int mid = (st + dr)>>1; /// aici fixez locatia
long long dist = 1LL * (mid-st) * v[mid] - get_sum (st,mid-1);
dist += get_sum (mid+1,dr) - 1LL * (dr - mid) * v[mid];
if (dist <= b)
return 1;
}
return 0;
}
int besthub (int n, int l, int x[], long long b){
for (int i=0;i<n;i++){
v[i+1] = x[i];
sp[i+1] = sp[i] + v[i+1];
}
int st = 1, dr = n, sol = 1;
while (st <= dr){
int mid = (st+dr)>>1;
if (verif(mid,n,b)){
sol = mid;
st = mid+1;
} else dr = mid-1;
}
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 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 |
# |
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 |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 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 |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 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 |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 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 |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
768 KB |
Output is correct |
3 |
Correct |
22 ms |
2944 KB |
Output is correct |
4 |
Correct |
21 ms |
2944 KB |
Output is correct |
5 |
Correct |
13 ms |
1408 KB |
Output is correct |
6 |
Correct |
13 ms |
1408 KB |
Output is correct |
7 |
Correct |
19 ms |
2688 KB |
Output is correct |
8 |
Correct |
19 ms |
2688 KB |
Output is correct |
9 |
Correct |
12 ms |
1408 KB |
Output is correct |
10 |
Correct |
14 ms |
1408 KB |
Output is correct |
11 |
Correct |
24 ms |
2944 KB |
Output is correct |
12 |
Correct |
23 ms |
2936 KB |
Output is correct |
13 |
Correct |
14 ms |
1536 KB |
Output is correct |
14 |
Correct |
14 ms |
1536 KB |
Output is correct |
15 |
Correct |
18 ms |
2304 KB |
Output is correct |
16 |
Correct |
19 ms |
2304 KB |
Output is correct |
17 |
Correct |
21 ms |
2688 KB |
Output is correct |
18 |
Correct |
22 ms |
2688 KB |
Output is correct |
19 |
Correct |
23 ms |
2944 KB |
Output is correct |
20 |
Correct |
22 ms |
2816 KB |
Output is correct |