Submission #511472

#TimeUsernameProblemLanguageResultExecution timeMemory
511472tabrBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
675 ms213920 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...