#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, s1, s2;
deque<int> first, second;
ll compute() {
int x;
if ((int) second.size() == (int) first.size()) {
x = second.front();
} else {
x = first.back();
}
ll cost = 0;
cost -= s1;
for (auto &p : first) {
cost += x;
}
cost += s2;
for (auto &p : second) {
cost += - x;
}
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]);
s2 += x[i];
if ((int) second.size() > (int) first.size()) {
s2 -= second.front();
s1 += second.front();
first.push_back(second.front());
second.pop_front();
}
while (compute() > b) {
if (first.empty()) {
second.pop_front();
} else {
first.pop_front();
}
if ((int) second.size() > (int) first.size()) {
s2 -= second.front();
s1 += second.front();
first.push_back(second.front());
second.pop_front();
}
}
sol = max(sol, (int) first.size() + (int) second.size());
}
return sol;
}
Compilation message
ricehub.cpp: In function 'll compute()':
ricehub.cpp:23:14: warning: unused variable 'p' [-Wunused-variable]
23 | for (auto &p : first) {
| ^
ricehub.cpp:27:14: warning: unused variable 'p' [-Wunused-variable]
27 | for (auto &p : second) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
105 ms |
476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |