Submission #791967

#TimeUsernameProblemLanguageResultExecution timeMemory
791967JosiaBoxes with souvenirs (IOI15_boxes)C++17
35 / 100
1 ms256 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define int int64_t long long delivery(signed N, signed K, signed L, signed p[]) { vector<int> left, right; for (int i = 0; i<N; i++) { if (p[i] <= L/2) left.push_back(p[i]); else right.push_back(L-p[i]); } sort(left.begin(), left.end()); sort(right.begin(), right.end()); auto leftO = left; auto rightO = right; long long res1 = L; for (int i = 0; i<K; i++) { if ((left.size() && right.empty()) || (left.size() && left.back() > right.back())) { left.pop_back(); } else if (right.size()) { right.pop_back(); } } while (left.size()) { res1 += left.back()*2; for (int i = 0; i<K; i++) { if (left.size()) left.pop_back(); } } while (right.size()) { res1 += right.back()*2; for (int i = 0; i<K; i++) { if (right.size()) right.pop_back(); } } left = leftO; right = rightO; long long res2 = 0; while (left.size()) { res2 += left.back()*2; for (int i = 0; i<K; i++) { if (left.size()) left.pop_back(); } } while (right.size()) { res2 += right.back()*2; for (int i = 0; i<K; i++) { if (right.size()) right.pop_back(); } } return min(res1, res2); }
#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...