#include "ricehub.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll get_sum(int l, int r, ll sum[]){
return (l==0) ? sum[r] : sum[r]-sum[l-1];
}
bool check(int l, int r, ll b, int v[], ll sum[]){
int med=(l+r)>>1;
ll act=(long long) v[med]*(med-l+1LL)-get_sum(l,med,sum);
act+=(long long) get_sum(med,r,sum)-v[med]*(r-med+1LL);
return act<=b;
}
int besthub(int n, int dist, int v[], ll b){
ll sum[n];
sum[0]=v[0];
for(int i=1;i<n;i++)
sum[i]=sum[i-1]+v[i];
int res=0;
for(int i=0;i<n;i++){
int l=i,r=n-1,act=0;
while(l<=r){
int med=(l+r)>>1;
if(check(i,med,b,v,sum)){
act=med;
l=med+1;
}
else r=med-1;
}
res=max(res,act-i+1);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 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 |
0 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 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 |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
252 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
460 KB |
Output is correct |
3 |
Correct |
22 ms |
1476 KB |
Output is correct |
4 |
Correct |
22 ms |
1480 KB |
Output is correct |
5 |
Correct |
10 ms |
844 KB |
Output is correct |
6 |
Correct |
10 ms |
880 KB |
Output is correct |
7 |
Correct |
20 ms |
1356 KB |
Output is correct |
8 |
Correct |
20 ms |
1384 KB |
Output is correct |
9 |
Correct |
10 ms |
888 KB |
Output is correct |
10 |
Correct |
10 ms |
888 KB |
Output is correct |
11 |
Correct |
22 ms |
1476 KB |
Output is correct |
12 |
Correct |
22 ms |
1468 KB |
Output is correct |
13 |
Correct |
10 ms |
800 KB |
Output is correct |
14 |
Correct |
10 ms |
844 KB |
Output is correct |
15 |
Correct |
17 ms |
1100 KB |
Output is correct |
16 |
Correct |
16 ms |
1168 KB |
Output is correct |
17 |
Correct |
25 ms |
1340 KB |
Output is correct |
18 |
Correct |
19 ms |
1228 KB |
Output is correct |
19 |
Correct |
22 ms |
1404 KB |
Output is correct |
20 |
Correct |
21 ms |
1416 KB |
Output is correct |