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 <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
long long delivery(int n, int k, int l, int p[]) {
vector<long long> dp1(n);
deque<pair<long long, int>> deq;
deq.emplace_front(0, -1);
for (int i = 0; i < n; i++) {
if (deq.front().second < i - k) {
deq.pop_front();
}
dp1[i] = deq.front().first + min(l, p[i] * 2);
while (!deq.empty() && deq.back().first >= dp1[i]) {
deq.pop_back();
}
deq.emplace_back(dp1[i], i);
}
deq.clear();
vector<long long> dp2(n);
deq.emplace_front(0, n);
for (int i = n - 1; i >= 0; i--) {
if (deq.front().second > i + k) {
deq.pop_front();
}
dp2[i] = deq.front().first + min(l, (l - p[i]) * 2);
while (!deq.empty() && deq.back().first >= dp2[i]) {
deq.pop_back();
}
deq.emplace_back(dp2[i], i);
}
long long res = min(dp1[n - 1], dp2[0]);
for (int i = 0; i < n - 1; i++) {
res = min(res, dp1[i] + dp2[i + 1]);
}
return res;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, l, p[100];
cin >> n >> k >> l;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
cout << delivery(n, k, l, p) << '\n';
return 0;
}
#endif
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |