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 "boxes.h"
#include<bits/stdc++.h>
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
if (K == 1){
long long ans = 0;
for (int i = 0;i<N;++i){
ans +=min(p[i],L - p[i]) * 2;
}
return ans;
}
else if (K == N){
long long ans = min({L,(L - p[0]) * 2,p[N - 1] * 2});
for (int i = 0;i<N - 1;++i){
ans = min(ans,(long long)p[i] * 2 + (L - p[i + 1]) * 2);
}
return ans;
}
else{
const long long mxn = 1e18;
long long ans = mxn;
vector<long long>l(N + 1,mxn),r(N + 1,mxn);
l[0] = 0;
r[0] = 0;
for (int i = 1;i<=N;++i){
int temp = max(i - K,0);
long long temp2 = 0;
if (i - 2 >=0)temp2 = p[i - 2];
l[i] = l[temp] + (p[i - 1] - temp2) * 2;
r[i] = r[temp] + (p[N - i] - p[i - 1]) * 2;
}
for (int i = 0;i<=N;++i){
ans = min(ans,l[i] + r[N - i]);
if (N - i - K>=0){
ans = min(ans,l[i] + r[N - i - K] + L);
}
}
return ans;
//first compute the total distance we have to travel to satisfy the teams
}
return 0;
}
# | 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... |