#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
ll n; ll place, cap;
vector<ll> v;
bool cmp(ll a, ll b) {
return abs(a-place) < abs(b-place);
}
ll calc(ll x) {
place = x;
sort(v.begin(),v.end(),cmp);
ll have = cap; ll ret = 0;
for(ll 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[], ll B) {
n = R; cap = B;
for(ll i = 0; i < R; i++) v.push_back(X[i]);
ll lo = 0, hi = L;
while(hi - lo >= 30) {
ll mid1 = (lo + lo + hi)/3;
ll mid2 = (lo + hi + hi)/3;
ll got1 = calc(mid1), got2 = calc(mid2);
if(got1 > got2) hi = mid2 - 1;
else lo = mid1 + 1;
}
ll ret = 0;
for(ll 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 |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
644 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
644 KB |
Output is correct |
8 |
Correct |
2 ms |
644 KB |
Output is correct |
9 |
Correct |
2 ms |
644 KB |
Output is correct |
10 |
Correct |
2 ms |
644 KB |
Output is correct |
11 |
Correct |
2 ms |
644 KB |
Output is correct |
12 |
Correct |
2 ms |
644 KB |
Output is correct |
13 |
Correct |
3 ms |
644 KB |
Output is correct |
14 |
Correct |
2 ms |
644 KB |
Output is correct |
15 |
Correct |
2 ms |
644 KB |
Output is correct |
16 |
Correct |
2 ms |
644 KB |
Output is correct |
17 |
Correct |
2 ms |
644 KB |
Output is correct |
18 |
Correct |
2 ms |
644 KB |
Output is correct |
19 |
Correct |
2 ms |
644 KB |
Output is correct |
20 |
Correct |
2 ms |
644 KB |
Output is correct |
21 |
Correct |
3 ms |
644 KB |
Output is correct |
22 |
Correct |
3 ms |
644 KB |
Output is correct |
23 |
Correct |
4 ms |
644 KB |
Output is correct |
24 |
Correct |
3 ms |
644 KB |
Output is correct |
25 |
Correct |
3 ms |
644 KB |
Output is correct |
26 |
Correct |
3 ms |
644 KB |
Output is correct |
27 |
Correct |
3 ms |
644 KB |
Output is correct |
28 |
Correct |
3 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
644 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
3 |
Correct |
5 ms |
644 KB |
Output is correct |
4 |
Correct |
5 ms |
644 KB |
Output is correct |
5 |
Correct |
3 ms |
644 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
4 ms |
644 KB |
Output is correct |
8 |
Correct |
3 ms |
644 KB |
Output is correct |
9 |
Correct |
3 ms |
644 KB |
Output is correct |
10 |
Correct |
3 ms |
644 KB |
Output is correct |
11 |
Correct |
5 ms |
644 KB |
Output is correct |
12 |
Correct |
4 ms |
644 KB |
Output is correct |
13 |
Correct |
5 ms |
644 KB |
Output is correct |
14 |
Correct |
6 ms |
644 KB |
Output is correct |
15 |
Correct |
4 ms |
644 KB |
Output is correct |
16 |
Correct |
3 ms |
644 KB |
Output is correct |
17 |
Correct |
4 ms |
644 KB |
Output is correct |
18 |
Correct |
4 ms |
644 KB |
Output is correct |
19 |
Correct |
7 ms |
644 KB |
Output is correct |
20 |
Correct |
7 ms |
644 KB |
Output is correct |
21 |
Correct |
11 ms |
756 KB |
Output is correct |
22 |
Correct |
12 ms |
756 KB |
Output is correct |
23 |
Correct |
20 ms |
756 KB |
Output is correct |
24 |
Correct |
29 ms |
756 KB |
Output is correct |
25 |
Correct |
27 ms |
756 KB |
Output is correct |
26 |
Correct |
28 ms |
756 KB |
Output is correct |
27 |
Correct |
25 ms |
756 KB |
Output is correct |
28 |
Correct |
25 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
1020 KB |
Output is correct |
2 |
Correct |
97 ms |
1024 KB |
Output is correct |
3 |
Correct |
825 ms |
2164 KB |
Output is correct |
4 |
Correct |
875 ms |
3316 KB |
Output is correct |
5 |
Correct |
184 ms |
3316 KB |
Output is correct |
6 |
Correct |
190 ms |
3316 KB |
Output is correct |
7 |
Correct |
456 ms |
4668 KB |
Output is correct |
8 |
Correct |
483 ms |
5448 KB |
Output is correct |
9 |
Correct |
181 ms |
5448 KB |
Output is correct |
10 |
Correct |
173 ms |
5448 KB |
Output is correct |
11 |
Correct |
850 ms |
7048 KB |
Output is correct |
12 |
Correct |
954 ms |
8216 KB |
Output is correct |
13 |
Incorrect |
293 ms |
8216 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |