#include "ricehub.h"
#include<bits/stdc++.h>
#define ll long long
int besthub(int n, int L, int X[], long long B)
{
ll a[n+1];
for(int i=1;i<=n;i++) a[i]=X[i-1];
ll pref[n+1]={0};
for(int i=1;i<=n;i++) pref[i]=pref[i-1]+a[i];
int l=1,r=n,res=1;
while(l<=r)
{
int mid=(l+r)/2;
bool bul=false;
for(int i=1;i+mid-1<=n;i++)
{
int j=(i+i+mid-1)/2;
ll x=a[j]*(j-i)-(pref[j-1]-pref[i-1])+pref[n]-pref[j]-a[j]*(n-j);
if(x<=B) bul=true;
j++;
x=a[j]*(j-i)-(pref[j-1]-pref[i-1])+pref[n]-pref[j]-a[j]*(n-j);
if(x<=B) bul=true;
}
if(bul)
{
res=mid;
l=mid+1;
}
else r=mid-1;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
2 |
Correct |
3 ms |
860 KB |
Output is correct |
3 |
Correct |
15 ms |
5212 KB |
Output is correct |
4 |
Correct |
10 ms |
5208 KB |
Output is correct |
5 |
Correct |
7 ms |
3676 KB |
Output is correct |
6 |
Correct |
8 ms |
3932 KB |
Output is correct |
7 |
Correct |
9 ms |
4956 KB |
Output is correct |
8 |
Correct |
9 ms |
4952 KB |
Output is correct |
9 |
Correct |
7 ms |
3676 KB |
Output is correct |
10 |
Correct |
8 ms |
3728 KB |
Output is correct |
11 |
Correct |
10 ms |
5300 KB |
Output is correct |
12 |
Correct |
10 ms |
5272 KB |
Output is correct |
13 |
Incorrect |
7 ms |
3672 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |