#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
int n; ll place, cap;
vector<int> v;
bool cmp(int a, int b) {
return abs(a-place) < abs(b-place);
}
int calc(ll x) {
place = x;
sort(v.begin(),v.end(),cmp);
ll have = cap; int 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[], ll 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
3 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
584 KB |
Output is correct |
2 |
Correct |
2 ms |
624 KB |
Output is correct |
3 |
Correct |
2 ms |
624 KB |
Output is correct |
4 |
Correct |
2 ms |
624 KB |
Output is correct |
5 |
Correct |
2 ms |
624 KB |
Output is correct |
6 |
Correct |
2 ms |
624 KB |
Output is correct |
7 |
Correct |
2 ms |
624 KB |
Output is correct |
8 |
Correct |
3 ms |
624 KB |
Output is correct |
9 |
Correct |
3 ms |
624 KB |
Output is correct |
10 |
Correct |
2 ms |
624 KB |
Output is correct |
11 |
Correct |
3 ms |
624 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
2 ms |
624 KB |
Output is correct |
14 |
Correct |
2 ms |
624 KB |
Output is correct |
15 |
Correct |
2 ms |
624 KB |
Output is correct |
16 |
Correct |
2 ms |
624 KB |
Output is correct |
17 |
Correct |
2 ms |
624 KB |
Output is correct |
18 |
Correct |
2 ms |
624 KB |
Output is correct |
19 |
Correct |
2 ms |
624 KB |
Output is correct |
20 |
Correct |
2 ms |
624 KB |
Output is correct |
21 |
Correct |
3 ms |
636 KB |
Output is correct |
22 |
Correct |
3 ms |
636 KB |
Output is correct |
23 |
Correct |
4 ms |
636 KB |
Output is correct |
24 |
Correct |
3 ms |
636 KB |
Output is correct |
25 |
Correct |
3 ms |
636 KB |
Output is correct |
26 |
Correct |
3 ms |
636 KB |
Output is correct |
27 |
Correct |
3 ms |
636 KB |
Output is correct |
28 |
Correct |
3 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
3 |
Correct |
5 ms |
636 KB |
Output is correct |
4 |
Correct |
5 ms |
756 KB |
Output is correct |
5 |
Correct |
2 ms |
756 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
4 ms |
756 KB |
Output is correct |
8 |
Correct |
3 ms |
756 KB |
Output is correct |
9 |
Correct |
4 ms |
756 KB |
Output is correct |
10 |
Correct |
3 ms |
756 KB |
Output is correct |
11 |
Correct |
4 ms |
756 KB |
Output is correct |
12 |
Correct |
4 ms |
756 KB |
Output is correct |
13 |
Correct |
6 ms |
756 KB |
Output is correct |
14 |
Correct |
5 ms |
756 KB |
Output is correct |
15 |
Correct |
3 ms |
756 KB |
Output is correct |
16 |
Correct |
3 ms |
756 KB |
Output is correct |
17 |
Correct |
4 ms |
756 KB |
Output is correct |
18 |
Correct |
6 ms |
756 KB |
Output is correct |
19 |
Correct |
5 ms |
756 KB |
Output is correct |
20 |
Correct |
6 ms |
756 KB |
Output is correct |
21 |
Correct |
9 ms |
756 KB |
Output is correct |
22 |
Correct |
10 ms |
764 KB |
Output is correct |
23 |
Correct |
15 ms |
764 KB |
Output is correct |
24 |
Correct |
18 ms |
764 KB |
Output is correct |
25 |
Correct |
24 ms |
764 KB |
Output is correct |
26 |
Correct |
25 ms |
764 KB |
Output is correct |
27 |
Correct |
23 ms |
764 KB |
Output is correct |
28 |
Correct |
23 ms |
764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
896 KB |
Output is correct |
2 |
Correct |
80 ms |
896 KB |
Output is correct |
3 |
Execution timed out |
1082 ms |
1656 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |