# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
519613 | silverfish | Boxes with souvenirs (IOI15_boxes) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
using ll = long long;
const int N = 10000007;
ll dp[N], s[N];
set<array<ll,2>> st;
long long delivery(int n, int k, int L, int p[]) {
ll l = L;
fill(dp, dp+N, 1e18+10);
sort(p, p+n);
for(int i = 0; i < n; ++i){
s[i] = (i ? dp[i-1] : 0) + min(2LL*(l-p[i]), l);
st.insert({s[i], i});
if(i-k >= 0) st.erase(st.find({s[i-k], i-k}));
auto it = st.begin();
int pos = (*it)[1];
dp[i] = dp[pos-1] + min({l, 2LL*p[i], 2LL*(l-p[pos]));
}
return dp[n-1];
}