Submission #401791

#TimeUsernameProblemLanguageResultExecution timeMemory
401791iulia13Boxes with souvenirs (IOI15_boxes)C++14
100 / 100
844 ms293984 KiB
#include "boxes.h" #include <iostream> #include <algorithm> using namespace std; #define ll long long const ll N = 1e7; ll dp1[N * 2]; ll dp2[N * 2]; ll delivery(int n, int k, int l, int p[]) { sort(p, p + n); ll ans = N * N; int i; ll L = l; for (i = 0; i < n; i++) { if (i < k) dp1[i] = min(1ll * p[i] * 2, L); else dp1[i] = min(1ll * p[i] * 2, L) + dp1[i - k]; } for (i = n - 1; 0 <= i; i--) { if (n - i <= k) dp2[i] = min(L, 1ll * (L - p[i]) * 2); else dp2[i] = min(L, 1ll * (L - p[i]) * 2) + dp2[i + k]; } ans = dp2[0]; for (i = 0; i < n; i++) ans = min(dp1[i] + dp2[i + 1], ans); return ans; }/* int n, k, l; int pp[N]; int main() { cin >> n >> k >> l; for (int i = 0; i < n; i++) cin >> pp[i]; cout << delivery(n, k, l, pp); return 0; } */
#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...