#include "ricehub.h"
#include <stdio.h>
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
/*
#define MAX_R 1000000
static int R, L;
static long long B;
static int X[MAX_R];
static int solution;
inline
void my_assert(int e) {if (!e) abort();}
static void read_input()
{
int i;
my_assert(3==scanf("%d %d %lld",&R,&L,&B));
for(i=0; i<R; i++)
my_assert(1==scanf("%d",&X[i]));
//my_assert(1==scanf("%d",&solution));
}
*/
int low,up,mid;
long long sum,pre[100005],suff[100005],v[100005],pos;
bool ok;
int besthub(int R, int L, int X[], long long B)
{
for(int i=1;i<=R;i++){
v[i]=X[i-1];
}
for(int i=1;i<=R;i++){
pre[i]=pre[i-1]+v[i];
}
for(int i=R;i>=1;i--){
suff[i]=suff[i+1]+(L-v[i]);
}
low=0;
up=R+1;
while(up-low>1){
mid=(up+low)/2;
ok=false;
for(int i=mid;i<=R;i++){
pos=(i+(i-mid+1))/2;
sum=suff[i-mid+1]-suff[pos]-(L-v[pos])*(pos-(i-mid+1));
sum+=pre[mid]-pre[pos]-v[pos]*(mid-pos);
if(sum<=B){
ok=true;
break;
}
}
if(ok)low=mid;
else up=mid;
}
return low;
}
/*
int main()
{
int ans;
read_input();
ans = besthub(R,L,X,B);
cout<<ans<<endl;
if(ans==solution)
printf("Correct.\n");
else
printf("Incorrect. Returned %d instead of %d.\n",ans,solution);
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |