#include <bits/stdc++.h>
#define ll long long
#define MAXR 100010
using namespace std;
ll pref[MAXR],a[MAXR];
ll Calc(ll L,ll R,ll pos)
{
ll l=L,r=R,mid,p;
while (l<=r)
{
mid=(l+r)/2;
if (a[mid]<=pos)
{
p=mid;
l=mid+1;
}
else
r=mid-1;
}
return pos*(p-L+1)-(pref[p]-pref[L-1])+pref[R]-pref[p]-pos*(R-p);
}
ll Check(ll x,ll n)
{
ll ans=LLONG_MAX;
for (ll i=1;i<=n-x+1;i++)
{
ll pos=(pref[i+x-1]-pref[i-1])/x;
if (pos>=a[i])
ans=min(ans,Calc(i,i+x-1,pos));
if (pos+1<=a[i+x-1])
ans=min(ans,Calc(i,i+x-1,pos+1));
}
return ans;
}
int besthub(int R,int L,int X[],ll B)
{
for (ll i=0;i<R;i++)
{
pref[i+1]=pref[i]+X[i];
a[i+1]=X[i];
}
int l=1,r=R,mid,ans;
while (l<=r)
{
mid=(l+r)/2;
if (Check(mid,R)<=B)
{
ans=mid;
l=mid+1;
}
else
r=mid-1;
}
return ans;
}
Compilation message
ricehub.cpp: In function 'long long int Calc(long long int, long long int, long long int)':
ricehub.cpp:20:31: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
20 | return pos*(p-L+1)-(pref[p]-pref[L-1])+pref[R]-pref[p]-pos*(R-p);
| ~~~~~~^
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:54:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
4 ms |
340 KB |
Output is correct |
22 |
Correct |
4 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
764 KB |
Output is correct |
2 |
Correct |
11 ms |
852 KB |
Output is correct |
3 |
Correct |
20 ms |
3404 KB |
Output is correct |
4 |
Correct |
16 ms |
3208 KB |
Output is correct |
5 |
Correct |
29 ms |
1620 KB |
Output is correct |
6 |
Correct |
26 ms |
1620 KB |
Output is correct |
7 |
Correct |
15 ms |
2916 KB |
Output is correct |
8 |
Correct |
16 ms |
3008 KB |
Output is correct |
9 |
Correct |
44 ms |
1468 KB |
Output is correct |
10 |
Correct |
52 ms |
1492 KB |
Output is correct |
11 |
Correct |
20 ms |
3308 KB |
Output is correct |
12 |
Correct |
19 ms |
3232 KB |
Output is correct |
13 |
Incorrect |
35 ms |
1620 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |