#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
bool check(int x[], int n, int siz, long long b){
int med = n/2;
long long f = 0;
long long s = 0;
for(int i = 0;i<=med;i++){
f+=x[med]-x[i];
}
for(int i = med+1;i<n;i++){
s+=x[i]-x[med];
}
for(int i = 1;i<=siz-n;i++){
f+=1LL*(x[med+i]-x[med+i-1])*(med+1);
f-=(x[med+i]-x[i-1]);
s-=1LL*(x[med+i]-x[med+i-1])*(n-med-1);
s+=(x[n+i-1]-x[med+i]);
if(f+s<b){
return 1;
}
}
return 0;
}
int besthub(int n, int l, int x[], long long b)
{
int lo = 0;
int hi = n;
while(lo<hi){
int mid = (lo+hi+1)/2;
if(check(x,mid,n,b)){
lo=mid;
}
else{
hi=mid-1;
}
}
return lo;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
456 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Incorrect |
10 ms |
1856 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |