#include<bits/stdc++.h>
using namespace std;
using lol=long long int;
bool ok(const vector<lol>& p,int n,lol B,int k)
{
auto query=[&](int l,int r){
if(l>r) return 0ll;
return p[r]-(l?p[l-1]:0);
};
for(int i=0;i+k-1<n;i++)
{
int pos=i+k/2;
lol chk=0;
if(i<=pos) chk+=(pos-i+1)*query(pos,pos)-query(i,pos);
if(pos+1<=i+k-1) chk+=query(pos+1,i+k-1)-(i+k-1-pos)*query(pos,pos);
if(chk<=B) return true;
}
return false;
}
int besthub(int R,int L,int X[],lol B)
{
vector<lol> p{X,X+R};
partial_sum(p.begin(),p.end(),p.begin());
int l=1,r=R,mid,ans;
while(l<=r)
{
mid=l+(r-l)/2;
if(ok(p,R,B,mid))
{
ans=mid;
l=mid+1;
}else r=mid-1;
}
return ans;
}
Compilation message
ricehub.cpp: In function 'int besthub(int, int, int*, lol)':
ricehub.cpp:36:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
300 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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
0 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
300 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
304 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 |
300 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
304 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 |
300 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
0 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 |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
568 KB |
Output is correct |
2 |
Correct |
4 ms |
588 KB |
Output is correct |
3 |
Correct |
13 ms |
2484 KB |
Output is correct |
4 |
Correct |
11 ms |
2420 KB |
Output is correct |
5 |
Correct |
7 ms |
1220 KB |
Output is correct |
6 |
Correct |
6 ms |
1220 KB |
Output is correct |
7 |
Correct |
10 ms |
2264 KB |
Output is correct |
8 |
Correct |
10 ms |
2256 KB |
Output is correct |
9 |
Correct |
9 ms |
1052 KB |
Output is correct |
10 |
Correct |
7 ms |
1080 KB |
Output is correct |
11 |
Correct |
11 ms |
2524 KB |
Output is correct |
12 |
Correct |
12 ms |
2512 KB |
Output is correct |
13 |
Correct |
7 ms |
1228 KB |
Output is correct |
14 |
Correct |
7 ms |
1196 KB |
Output is correct |
15 |
Correct |
10 ms |
1860 KB |
Output is correct |
16 |
Correct |
9 ms |
1856 KB |
Output is correct |
17 |
Correct |
12 ms |
2272 KB |
Output is correct |
18 |
Correct |
11 ms |
2244 KB |
Output is correct |
19 |
Correct |
13 ms |
2352 KB |
Output is correct |
20 |
Correct |
13 ms |
2352 KB |
Output is correct |