#include "ricehub.h"
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
int besthub(int R, int L, int X[], long long B)
{
ll ans=1;
ll plus,l,r;
l=1;
r=R;
bool ok=false;
while(l<r)
{
ok=false;
plus=(l+r)/2;
bool pre=false;
ll curr=0;
for(int i=0;i<=R-plus;i++)
{
ll med;
if(!pre)
{
med=(i+i+plus-1)/2;
for(int j=i;j<i+plus;j++)
curr+=abs(X[med]-X[j]);
pre=true;
}
else
{
med++;
ll dif=abs(X[med]-X[med-1]);
curr+=abs(i-med)*dif;
curr-=(plus-abs(i-med-1))*dif;
curr+=abs(X[med]-X[i+plus-1]);
curr-=abs(X[med-1]-X[i-1]);
}
if(curr<=B)
{
ans=max(plus,ans);
ok=true;
break;
}
}
if(plus==l || plus==r)
break;
if(ok)
l=plus;
else
r=plus;
}
//cout<<'\n'<<ans<<'\n';
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
368 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Incorrect |
13 ms |
656 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |