이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int n, int L, int a[], long long cmax) {
long long curcost = 0;
int sol, cursol = 1;
queue<int> l, r;
l.emplace(0);
for (int i = 1; i < n; ++i)
r.emplace(i);
while (!r.empty() && a[r.front()] - a[0] <= cmax - curcost) {
++cursol, curcost += a[r.front()] - a[0];
r.pop();
}
sol = cursol;
for (int i = 1; i < n; ++i) {
curcost += 1LL * (a[i] - a[i - 1]) * l.size();
curcost -= 1LL * (a[i] - a[i - 1]) * (cursol - l.size());
while (!l.empty() && curcost > cmax) {
curcost -= a[i] - a[l.front()];
--cursol;
l.pop();
}
while (!r.empty() && a[r.front()] - a[i] <= cmax - curcost) {
++cursol;
curcost += a[r.front()] - a[i];
r.pop();
}
while (!r.empty() && a[r.front()] - a[i] - (l.empty() ? 0 : a[i] - a[l.front()]) <= 0) {
cursol += l.empty();
curcost += a[r.front()] - a[i] - (l.empty() ? 0 : a[i] - a[l.front()]);
if (!l.empty())
l.pop();
r.pop();
}
l.emplace(i);
sol = max(sol, cursol);
}
return sol;
}
# | 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... |