#include <bits/stdc++.h>
#include <ricehub.h>
#define DEBUG 0
using namespace std;
int cost(int n, int X[], int mid, long long B) {
deque <int> L, R;
for(int i = 0; i < n; i++) {
if(X[i] <= mid) {
L.push_front(mid - X[i]);
}
else {
R.push_back(X[i] - mid);
}
}
int i = 0, j = 0;
long long sum = 0;
while(i < L.size() && j < R.size()) {
if(L[i] <= R[j]) {
sum += L[i++];
}
else {
sum += R[j++];
}
if(sum > B) {
return i + j - 1;
}
}
while(i < L.size()) {
sum += L[i++];
if(sum > B) {
return i + j - 1;
}
}
while(j < R.size()) {
sum += R[j++];
if(sum > B) {
return i + j - 1;
}
}
return n;
}
int besthub(int R, int L, int X[], long long B) {
int l = 1, r = L, ans = 0, mid, cost1;
int l2, r2, mid2, pos2, cost2;
while(l <= r) {
mid = (l + r) / 2;
cost1 = cost(R, X, mid, B);
l2 = l + 1, r2 = r, pos2 = r;
while(l2 <= r2) {
mid2 = (l2 + r2) / 2;
if(cost1 == cost(R, X, mid2, B)) {
l2 = mid2 + 1;
}
else {
r2 = mid2 - 1;
pos2 = min(pos2, mid2);
}
}
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;
}
Compilation message
ricehub.cpp: In function 'int cost(int, int*, int, long long int)':
ricehub.cpp:18:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | while(i < L.size() && j < R.size()) {
| ~~^~~~~~~~~~
ricehub.cpp:18:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | while(i < L.size() && j < R.size()) {
| ~~^~~~~~~~~~
ricehub.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | while(i < L.size()) {
| ~~^~~~~~~~~~
ricehub.cpp:35:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | while(j < R.size()) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
308 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
312 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
316 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
212 KB |
Output is correct |
20 |
Correct |
5 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
324 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
344 KB |
Output is correct |
24 |
Correct |
8 ms |
384 KB |
Output is correct |
25 |
Correct |
22 ms |
340 KB |
Output is correct |
26 |
Correct |
19 ms |
392 KB |
Output is correct |
27 |
Correct |
11 ms |
340 KB |
Output is correct |
28 |
Correct |
13 ms |
388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
608 KB |
Output is correct |
2 |
Correct |
17 ms |
608 KB |
Output is correct |
3 |
Correct |
351 ms |
2168 KB |
Output is correct |
4 |
Correct |
499 ms |
2256 KB |
Output is correct |
5 |
Incorrect |
34 ms |
980 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |