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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <cmath>
#include <climits>
#include <cstring>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
ll delivery(int n, int k, int l, int pos[]){
ll dp1[n], dp2[n];
for (ll i = 0; i < n; i++){
if (i >= k)
dp1[i] = dp1[i - k] + 2*pos[i];
else
dp1[i] = 2*pos[i];
}
for (ll i = n - 1; i >= 0; i--){
if ((n - 1) - i >= k)
dp2[(n - 1) - i] = dp2[(n - 1) - i - k] + 2*(l - pos[i]);
else
dp2[(n - 1) - i] = 2*(l - pos[i]);
}
ll res = min(dp1[n - 1], dp2[n - 1]);
if (n >= k + 1)
res = min(res, l + dp2[n - 1 - k]);
if (n == k)
res = min(res, (ll)l);
for (ll i = 0; i < n - 1; i++){
res = min(res, dp1[i] + dp2[n - i - 2]);
if (n - i - 2 == k - 1)
res = min(res, dp1[i] + l);
if (n - i - 2 >= k)
res = min(res, dp1[i] + l + dp2[n - i - 2 - k]);
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |