#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b;
int r, l, x[100005];
bool possi(ll lcnt,ll rcnt) {
ll ret = 0x3f3f3f3f3f3f3f3f;
deque<int> le, ri;
ll sum = 0;
for (int i = 0; i < r; i++) {
if (le.size() < lcnt) {
le.push_back(i);
sum -= x[i];
}
else if (ri.size() < rcnt) {
ri.push_back(i);
sum += x[i];
}
else {
sum += x[le.front()];
le.pop_front();
sum -= x[ri.front()];
sum -= x[ri.front()];
le.push_back(ri.front());
ri.pop_front();
ri.push_back(i);
sum += x[i];
}
if (le.size() == lcnt && ri.size() == rcnt) {
ret = min(ret, sum + lcnt * x[ri.front()] - rcnt * x[ri.front()]);
}
}
return ret <= b;
}
int besthub(int R, int L, int X[], long long B)
{
r = R; l = L; b = B;
for (int i = 0; i < r; i++)
x[i] = X[i];
sort(x, x + r);
int le, ri, mid, ans;
ans = 1;
le = 2;
ri = r;
while (le <= ri) {
mid = (le + ri) / 2;
if (possi(mid/2,mid-mid/2)) {
ans = mid;
le = mid + 1;
}
else
ri = mid - 1;
}
return ans;
}
Compilation message
ricehub.cpp: In function 'bool possi(ll, ll)':
ricehub.cpp:12:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (le.size() < lcnt) {
^
ricehub.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if (ri.size() < rcnt) {
^
ricehub.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (le.size() == lcnt && ri.size() == rcnt) {
^
ricehub.cpp:30:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (le.size() == lcnt && ri.size() == rcnt) {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
568 KB |
Output is correct |
2 |
Correct |
1 ms |
568 KB |
Output is correct |
3 |
Correct |
2 ms |
568 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
732 KB |
Output is correct |
12 |
Correct |
1 ms |
732 KB |
Output is correct |
13 |
Correct |
2 ms |
732 KB |
Output is correct |
14 |
Correct |
2 ms |
732 KB |
Output is correct |
15 |
Correct |
1 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
732 KB |
Output is correct |
21 |
Correct |
2 ms |
732 KB |
Output is correct |
22 |
Correct |
2 ms |
732 KB |
Output is correct |
23 |
Correct |
2 ms |
732 KB |
Output is correct |
24 |
Correct |
2 ms |
732 KB |
Output is correct |
25 |
Correct |
2 ms |
732 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
2 ms |
732 KB |
Output is correct |
28 |
Correct |
2 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
732 KB |
Output is correct |
2 |
Correct |
2 ms |
732 KB |
Output is correct |
3 |
Correct |
2 ms |
732 KB |
Output is correct |
4 |
Correct |
2 ms |
740 KB |
Output is correct |
5 |
Correct |
2 ms |
740 KB |
Output is correct |
6 |
Correct |
2 ms |
740 KB |
Output is correct |
7 |
Correct |
3 ms |
740 KB |
Output is correct |
8 |
Correct |
2 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
2 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
21 |
Correct |
4 ms |
740 KB |
Output is correct |
22 |
Correct |
3 ms |
740 KB |
Output is correct |
23 |
Correct |
3 ms |
740 KB |
Output is correct |
24 |
Correct |
3 ms |
740 KB |
Output is correct |
25 |
Correct |
3 ms |
740 KB |
Output is correct |
26 |
Correct |
3 ms |
740 KB |
Output is correct |
27 |
Correct |
3 ms |
740 KB |
Output is correct |
28 |
Correct |
3 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
860 KB |
Output is correct |
2 |
Correct |
9 ms |
860 KB |
Output is correct |
3 |
Correct |
33 ms |
2000 KB |
Output is correct |
4 |
Correct |
39 ms |
2000 KB |
Output is correct |
5 |
Correct |
20 ms |
2000 KB |
Output is correct |
6 |
Correct |
20 ms |
2000 KB |
Output is correct |
7 |
Correct |
34 ms |
2000 KB |
Output is correct |
8 |
Correct |
30 ms |
2000 KB |
Output is correct |
9 |
Correct |
19 ms |
2000 KB |
Output is correct |
10 |
Correct |
29 ms |
2000 KB |
Output is correct |
11 |
Correct |
33 ms |
2000 KB |
Output is correct |
12 |
Correct |
38 ms |
2000 KB |
Output is correct |
13 |
Correct |
21 ms |
2000 KB |
Output is correct |
14 |
Correct |
22 ms |
2000 KB |
Output is correct |
15 |
Correct |
26 ms |
2000 KB |
Output is correct |
16 |
Correct |
33 ms |
2000 KB |
Output is correct |
17 |
Correct |
30 ms |
2000 KB |
Output is correct |
18 |
Correct |
33 ms |
2000 KB |
Output is correct |
19 |
Correct |
35 ms |
2000 KB |
Output is correct |
20 |
Correct |
34 ms |
2000 KB |
Output is correct |