#include "ricehub.h"
#include <iostream>
#include <cmath>
typedef long long ll;
using namespace std;
bool ok (ll x, int R,int L,int X[],long long B){
ll i = x;
ll cost = 0;
ll med = ((i)/2);
for(ll j = 0;j<i;j++){
cost += abs(X[med]-X[j]);
}
if(cost<=B){ return 1;}
for(ll j = 1;j<=R-i;j++){
med++;
cost += (i/2-(i-1)/2)*(X[med]-X[med-1]);
cost += abs(X[med]-X[j+i-1]);
cost -= abs(X[med-1]-X[j-1]);
if(cost<=B){return 1;}
}
return 0;
}
int besthub(int R, int L, int X[], long long B)
{
ll l = 1 ; ll r = R;
ll anss = 1;
while(l<r){
ll m = (l+r)>>1;
if (ok(m,R,L,X,B))
{
anss = max (anss, ll(m));
l = m;
}
else{
r = m - 1;
}
}
return anss;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1074 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1065 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |