Submission #674842

#TimeUsernameProblemLanguageResultExecution timeMemory
674842benjaminkleynBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
729 ms288184 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; typedef long long ll; ll delivery(int n, int k, int l, int p[]) { sort(p, p + n); vector<ll> pref(n + 1, 0); for (int i = 1; i <= k; i++) pref[i] = p[i-1]; for (int i = k + 1; i <= n; i++) pref[i] = p[i-1] + pref[i - k]; vector<ll> suff(n + 2, 0); for (int i = n; i > n - k; i--) suff[i] = (l - p[i-1]); for (int i = n - k; i >= 1; i--) suff[i] = (l - p[i-1]) + suff[i + k]; ll ans = LLONG_MAX; for (int i = 1; i + k - 1 <= n; i++) ans = min(ans, l + 2 * pref[i - 1] + 2 * suff[i + k]); for (int i = 1; i <= n + 1; i++) ans = min(ans, 2 * pref[i - 1] + 2 * suff[i]); 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...