# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
787057 | JoenPoenMan | Rice Hub (IOI11_ricehub) | C++17 | 1069 ms | 2072 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ALL(arr) begin(arr), end(arr)
#define CONTAINS(arr, val) (find(ALL(arr), val) == end(arr))
typedef pair<int, int> ii;
int besthub(int R, int L, int X[], long long B)
{
vector<int> crs;
stack<ii> removed;
long long cost = 0;
int i = 0;
int best = 0;
long long dc = 0;
for (int x = 1; x <= L && i < R; x++)
{
while (!removed.empty() && removed.top().first + x - removed.top().second <= B - cost) {
crs.insert(crs.begin(), removed.top().first + x - removed.top().second);
cost += crs[0];
dc++;
removed.pop();
}
while (i < R && cost + (X[i]-x) <= B) {
crs.push_back(x - X[i]);
cost += X[i]-x;
dc--;
i++;
}
while (crs.size() && i < R && (X[i]-x) <= crs[0]) {
cost -= crs[0];
removed.push({crs[0], x});
crs.erase(crs.begin());
crs.push_back(x - X[i]);
cost += X[i]-x;
dc -= 2;
i++;
}
while (i < R && cost + (X[i]-x) <= B) {
crs.push_back(x - X[i]);
cost += X[i]-x;
dc--;
i++;
}
best = max(best, (int)crs.size());
for (int &el : crs) {
if (el == 0) {
dc += 2;
}
el++;
}
cost += dc;
while (cost > B) {
cost -= crs[0];
removed.push({crs[0], x});
crs.erase(crs.begin());
dc--;
}
if (R-1 - i < best - crs.size()) break;
}
return best;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |