#include <iostream>
#include "ricehub.h"
using namespace std;
int besthub(int R, int L,int X[], long long int B){
long long int izq=0, der=0, maxim=0;
long long int costo=0;
int i=0,j=0;
int z=0;
while(i<R){
if(j==R-1||costo>B) {
if(izq<der){
z=(i+j)/2;
costo-=X[z+1]-X[z-izq];
costo+=(X[z+1]-X[z])*(izq);
costo-=(X[z+1]-X[z])*(der);
izq++;
der--;
}
i++;
izq--;
}
else{
z=(i+j)/2;
if(izq<der){
costo+=X[z+1+der]-X[z+1];
costo+=(X[z+1]-X[z])*izq;
costo-=(X[z+1]-X[z])*(der-1);
izq++;
der--;
}
else{
costo+=X[z+der+1]-X[z];
}
j++;
der++;
}
if(costo<=B) maxim=max(maxim,der+izq+1);
}
return maxim;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
436 KB |
Output is correct |
2 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |