#include<bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int p[100005];
bool f(int k, int n, long long B){
if(k==0) return true;
int med = k/2;
long long D = 0;
for(int i = 0; i < k; i++){
D+=abs(p[med]-p[i]);
}
long long d = D;
for(int l = 1; l+k<=n; l++){
D-=abs(p[med]-p[l-1]);
med++;
D+=abs(p[med]-p[(l+k)-1]);
d = min(d, D);
}
return d <= B;
}
int besthub(int n, int L, int x[], long long B)
{
for(int i = 0; i < n; i++){
p[i] = x[i];
}
int ini = 0, fin = n;
while(ini+1<fin){
int mit = (ini+fin)/2;
if(f(mit,n,B)){
ini = mit;
}else{
fin = mit-1;
}
}
if(f(fin,n,B)) return fin;
return ini;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
588 KB |
Output is correct |
2 |
Incorrect |
3 ms |
588 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |