Submission #431853

#TimeUsernameProblemLanguageResultExecution timeMemory
431853muhammad_hokimiyonBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
1030 ms352740 KiB
#include "boxes.h" #include <bits/stdc++.h> #define fi first #define se second #define ll long long #define dl double using namespace std; ll delivery(int N, int K, int LE, int P[]) { vector<ll> d(N + 1, 1e18); d[0] = 0; vector<ll> p(N + 1, 0); for(int i = 1; i <= N; i++)p[i] = P[i - 1]; sort(p.begin(), p.end()); vector<ll> L(N + 1, 0ll), R(N + 2, 0ll); for(int i = 1; i <= N; i++){ L[i] = L[max(0, i - K)] + p[i] + p[i]; } for(int i = N; i >= 1; i--){ R[i] = R[min(N + 1, i + K)] + (LE - p[i]) * 2ll; } ll ans = 1e18; for(int i = 0; i <= N; i++){ ans = min(ans, L[i] + R[i + 1]); } for(int i = 1; i <= N; i++){ if(i + K - 1 > N)break; ans = min(ans, L[i - 1] + R[i + K] + LE); } return ans; }
#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...