#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int n, place, cap;
vector<int> v;
bool cmp(int a, int b) {
return abs(a-place) < abs(b-place);
}
int calc(int x) {
place = x;
sort(v.begin(),v.end(),cmp);
int have = cap, ret = 0;
for(int i = 0; i < n; i++) {
if(abs(v[i]-x) > have) break;
have -= abs(v[i]-x);
ret++;
} return ret;
}
int besthub(int R, int L, int X[], long long B)
{
n = R; cap = B;
for(int i = 0; i < R; i++) v.push_back(X[i]);
int lo = 0, hi = L;
while(hi - lo >= 10) {
int mid1 = (lo + lo + hi)/3;
int mid2 = (lo + hi + hi)/3;
int got1 = calc(mid1), got2 = calc(mid2);
if(got1 > got2) hi = mid2 - 1;
else lo = mid1 + 1;
}
int ret = 0;
for(int i = lo; i <= hi; i++)
ret = max(ret , calc(i));
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
448 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
580 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
676 KB |
Output is correct |
17 |
Correct |
2 ms |
676 KB |
Output is correct |
18 |
Correct |
2 ms |
676 KB |
Output is correct |
19 |
Correct |
2 ms |
688 KB |
Output is correct |
20 |
Correct |
2 ms |
688 KB |
Output is correct |
21 |
Correct |
3 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
840 KB |
Output is correct |
23 |
Correct |
4 ms |
840 KB |
Output is correct |
24 |
Correct |
3 ms |
840 KB |
Output is correct |
25 |
Correct |
3 ms |
840 KB |
Output is correct |
26 |
Correct |
4 ms |
840 KB |
Output is correct |
27 |
Correct |
3 ms |
840 KB |
Output is correct |
28 |
Correct |
3 ms |
840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
840 KB |
Output is correct |
2 |
Correct |
2 ms |
840 KB |
Output is correct |
3 |
Correct |
5 ms |
840 KB |
Output is correct |
4 |
Correct |
5 ms |
840 KB |
Output is correct |
5 |
Correct |
3 ms |
840 KB |
Output is correct |
6 |
Correct |
2 ms |
840 KB |
Output is correct |
7 |
Correct |
3 ms |
840 KB |
Output is correct |
8 |
Correct |
4 ms |
840 KB |
Output is correct |
9 |
Correct |
3 ms |
840 KB |
Output is correct |
10 |
Correct |
3 ms |
840 KB |
Output is correct |
11 |
Correct |
4 ms |
840 KB |
Output is correct |
12 |
Correct |
4 ms |
840 KB |
Output is correct |
13 |
Correct |
4 ms |
840 KB |
Output is correct |
14 |
Correct |
5 ms |
840 KB |
Output is correct |
15 |
Correct |
3 ms |
844 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
4 ms |
852 KB |
Output is correct |
18 |
Correct |
4 ms |
860 KB |
Output is correct |
19 |
Correct |
5 ms |
868 KB |
Output is correct |
20 |
Correct |
6 ms |
876 KB |
Output is correct |
21 |
Correct |
9 ms |
1004 KB |
Output is correct |
22 |
Correct |
12 ms |
1004 KB |
Output is correct |
23 |
Correct |
15 ms |
1004 KB |
Output is correct |
24 |
Correct |
18 ms |
1064 KB |
Output is correct |
25 |
Correct |
24 ms |
1064 KB |
Output is correct |
26 |
Correct |
25 ms |
1168 KB |
Output is correct |
27 |
Correct |
22 ms |
1168 KB |
Output is correct |
28 |
Correct |
23 ms |
1168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
1540 KB |
Output is correct |
2 |
Correct |
74 ms |
1676 KB |
Output is correct |
3 |
Incorrect |
57 ms |
3476 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |