Submission #376056

#TimeUsernameProblemLanguageResultExecution timeMemory
376056MilosMilutinovic선물상자 (IOI15_boxes)C++14
20 / 100
1 ms512 KiB
/** * author: milos * created: 10.03.2021 17:16:12 **/ #include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int n, int k, int l, int* a) { assert(k <= n); sort(a, a + n); vector<long long> pref(n, 0LL); for (int i = 0; i < n; i++) { if (i >= k) { pref[i] = pref[i - k]; } pref[i] += 2 * a[i]; } vector<long long> suff(n, 0LL); for (int i = n - 1; i >= 0; i--) { if (i < n - 1) { suff[i] = suff[i + 1]; } if ((n - i - 1) % k != 0) { suff[i] -= (l - a[i + 1]) * 2; } suff[i] += (l - a[i]) * 2; } /*for (int i = 0; i < n; i++) { cout << pref[i] << " "; } cout << '\n'; for (int i = 0; i < n; i++) { cout << suff[i] << " "; } cout << '\n';*/ long long ans = suff[0]; for (int i = 0; i < n; i++) { ans = min(ans, pref[i] + (i < n - 1 ? suff[i + 1] : 0LL)); } if (k >= ans) { ans = min(ans, (long long) l); } ans = min(ans, suff[k] + l); for (int i = 0; i < n; i++) { ans = min(ans, pref[i] + (i < n - k - 1 ? suff[i + k + 1] : 0LL) + l); } 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...