#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];
}
if(f+s<b)
return 1;
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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
1 ms |
352 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
15 ms |
1884 KB |
Output is correct |
4 |
Correct |
10 ms |
1884 KB |
Output is correct |
5 |
Correct |
4 ms |
988 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
10 ms |
1372 KB |
Output is correct |
8 |
Correct |
8 ms |
1596 KB |
Output is correct |
9 |
Correct |
4 ms |
860 KB |
Output is correct |
10 |
Correct |
4 ms |
716 KB |
Output is correct |
11 |
Correct |
16 ms |
1736 KB |
Output is correct |
12 |
Correct |
9 ms |
1884 KB |
Output is correct |
13 |
Correct |
5 ms |
908 KB |
Output is correct |
14 |
Correct |
4 ms |
860 KB |
Output is correct |
15 |
Correct |
9 ms |
1328 KB |
Output is correct |
16 |
Correct |
8 ms |
1500 KB |
Output is correct |
17 |
Correct |
12 ms |
1648 KB |
Output is correct |
18 |
Correct |
10 ms |
1628 KB |
Output is correct |
19 |
Correct |
9 ms |
1592 KB |
Output is correct |
20 |
Correct |
8 ms |
1740 KB |
Output is correct |