#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxN=1e5+5;
ll sum[maxN+1];
int a[maxN+1];
ll get(ll l,ll r)
{
if(l==0)
{
return sum[r];
}
else return sum[r]-sum[l-1];
}
bool check(ll len,int n,ll B,int a[])
{
ll l=0,r=len-1;
while(r<n)
{
ll p=(l+r)/2;
ll cur=(p-l+1)*a[p]-get(l,p)+get(p,r)-(r-p+1)*a[p];
if(cur<=B)
{
return true;
}
l++;
r++;
}
return false;
}
ll besthub(int n,int L,int a[],ll B)
{
sum[0]=a[0];
for(int i=1;i<n;i++)
{
sum[i]=sum[i-1]+a[i];
}
ll res,l=1,r=n;
while(l<=r)
{
ll mid=(l+r)/2;
if(check(mid,n,B,a))
{
res=mid;
l=mid+1;
}
else r=mid-1;
}
return res;
}
/*5 20 6
1 2 10 12 14*/
Compilation message
ricehub.cpp: In function 'long long int besthub(int, int, int*, long long int)':
ricehub.cpp:49:12: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | return res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2400 KB |
Output is correct |
20 |
Correct |
1 ms |
2492 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
9 ms |
2396 KB |
Output is correct |
4 |
Correct |
9 ms |
2396 KB |
Output is correct |
5 |
Correct |
5 ms |
2396 KB |
Output is correct |
6 |
Correct |
5 ms |
2396 KB |
Output is correct |
7 |
Correct |
7 ms |
2488 KB |
Output is correct |
8 |
Correct |
8 ms |
2396 KB |
Output is correct |
9 |
Correct |
5 ms |
2396 KB |
Output is correct |
10 |
Correct |
5 ms |
2396 KB |
Output is correct |
11 |
Correct |
10 ms |
2492 KB |
Output is correct |
12 |
Correct |
9 ms |
2500 KB |
Output is correct |
13 |
Correct |
5 ms |
2492 KB |
Output is correct |
14 |
Correct |
5 ms |
2488 KB |
Output is correct |
15 |
Correct |
7 ms |
2396 KB |
Output is correct |
16 |
Correct |
7 ms |
2396 KB |
Output is correct |
17 |
Correct |
10 ms |
2396 KB |
Output is correct |
18 |
Correct |
8 ms |
2392 KB |
Output is correct |
19 |
Correct |
8 ms |
2396 KB |
Output is correct |
20 |
Correct |
8 ms |
2500 KB |
Output is correct |