#include <bits/stdc++.h>
#include <ricehub.h>
#define DEBUG 0
using namespace std;
int cost(int R, int X[], int pos, long long B) {
vector <int> truckload;
for(int i = 0; i < R; i++) {
truckload.push_back(abs(X[i] - pos));
}
sort(truckload.begin(), truckload.end());
long long sum = 0;
for(int i = 0; i < R; i++) {
if(sum + truckload[i] > B) {
return i;
}
sum += truckload[i];
}
return R;
}
int besthub(int R, int L, int X[], long long B) {
int l = 1, r = L, ans = 0;
while(l <= r) {
int mid = (l + r) / 2;
int cost1 = cost(R, X, mid, B);
int l2 = l + 1, r2 = r, pos2 = r;
while(l2 <= r2) {
int mid2 = (l2 + r2) / 2;
int cost2 = cost(R, X, mid2, B);
if(cost1 == cost2) {
l2 = mid2 + 1;
}
else {
r2 = mid2 - 1;
pos2 = min(pos2, mid2);
}
}
int cost2 = cost(R, X, pos2, B);
if(cost1 > cost2) {
r = mid - 1;
ans = max(ans, cost1);
}
else {
l = mid + 1;
ans = max(ans, cost2);
}
}
return ans;
}
// int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// int r, l, b;
// cin >> r >> l >> b;
// int x[l];
// for(int i = 0; i < r; i++) {
// cin >> x[i];
// }
// cout << besthub(r, l, x, b);
// return 0;
// }
/*
5 20 6
1 2 10 12 14
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
3 ms |
204 KB |
Output is correct |
24 |
Correct |
3 ms |
204 KB |
Output is correct |
25 |
Correct |
3 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
204 KB |
Output is correct |
4 |
Correct |
7 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
204 KB |
Output is correct |
12 |
Correct |
3 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
4 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
3 ms |
204 KB |
Output is correct |
19 |
Correct |
3 ms |
316 KB |
Output is correct |
20 |
Correct |
8 ms |
204 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
332 KB |
Output is correct |
23 |
Correct |
9 ms |
332 KB |
Output is correct |
24 |
Correct |
21 ms |
332 KB |
Output is correct |
25 |
Correct |
79 ms |
332 KB |
Output is correct |
26 |
Correct |
67 ms |
356 KB |
Output is correct |
27 |
Correct |
23 ms |
332 KB |
Output is correct |
28 |
Correct |
22 ms |
372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
588 KB |
Output is correct |
2 |
Correct |
283 ms |
764 KB |
Output is correct |
3 |
Correct |
788 ms |
1928 KB |
Output is correct |
4 |
Execution timed out |
1084 ms |
1812 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |