#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
const int N = 100000 + 7;
int n, len, x[N];
ll b, s_first, s_second;
deque<int> first, second;
ll compute() {
int x;
if ((int) second.size() == (int) first.size()) {
x = second.front();
} else {
x = first.back();
}
ll cost = s_second - s_first;
cost += (ll) x * (int) first.size();
cost -= (ll) x * (int) second.size();
return cost;
}
int besthub(int r, int dim, int rice_fields[], ll gold_coins) {
n = r;
len = dim;
for (int i = 1; i <= n; i++) {
x[i] = rice_fields[i - 1];
}
b = gold_coins;
int sol = 0;
for (int i = 1; i <= n; i++) {
second.push_back(x[i]);
s_second += x[i];
if ((int) second.size() > (int) first.size()) {
s_second -= second.front();
s_first += second.front();
first.push_back(second.front());
second.pop_front();
}
while (compute() > b) {
if (first.empty()) {
s_second -= second.front();
second.pop_front();
} else {
s_first -= first.front();
first.pop_front();
}
if ((int) second.size() > (int) first.size()) {
s_second -= second.front();
s_first += second.front();
first.push_back(second.front());
second.pop_front();
}
}
sol = max(sol, (int) first.size() + (int) second.size());
}
return sol;
}
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
16 ms |
1484 KB |
Output is correct |
4 |
Correct |
16 ms |
2532 KB |
Output is correct |
5 |
Correct |
8 ms |
1040 KB |
Output is correct |
6 |
Correct |
8 ms |
972 KB |
Output is correct |
7 |
Correct |
14 ms |
2256 KB |
Output is correct |
8 |
Correct |
14 ms |
2224 KB |
Output is correct |
9 |
Correct |
7 ms |
972 KB |
Output is correct |
10 |
Correct |
8 ms |
972 KB |
Output is correct |
11 |
Correct |
17 ms |
2528 KB |
Output is correct |
12 |
Correct |
16 ms |
2584 KB |
Output is correct |
13 |
Correct |
8 ms |
972 KB |
Output is correct |
14 |
Correct |
9 ms |
972 KB |
Output is correct |
15 |
Correct |
12 ms |
1920 KB |
Output is correct |
16 |
Correct |
15 ms |
1892 KB |
Output is correct |
17 |
Correct |
14 ms |
2308 KB |
Output is correct |
18 |
Correct |
14 ms |
2328 KB |
Output is correct |
19 |
Correct |
15 ms |
2380 KB |
Output is correct |
20 |
Correct |
15 ms |
2336 KB |
Output is correct |