제출 #376046

#제출 시각아이디문제언어결과실행 시간메모리
376046MilosMilutinovicBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
1 ms364 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) { sort(a, a + n); vector<long long> pref(n, 0LL); for (int i = 0; i < n; i++) { if (i > 0) { pref[i] = pref[i - 1]; } if (i % k != 0) { pref[i] -= a[i - 1] * 2; } pref[i] += a[i] * 2; } 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; } 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 == n) { ans = min(ans, (long long) l); } else { ans = min(ans, (long long) l + suff[n - k - 1]); } 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...