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;
const int MN=1e7+10;
pair<long long,int> dp[MN];
long long delivery(int n, int k, int l, int p[]) {
sort(p,p+n);
dp[0]={2*p[0],k-1};
for(int i=1;i<n;i++){
dp[i]=dp[i-1];
if(dp[i-1].second){
dp[i].second--;
dp[i].first+=p[i]-p[i-1];
dp[i].first+=min(p[i],l-p[i])-min(p[i-1],l-p[i-1]);
}
else{
dp[i].second=k-1;
dp[i].first+=min(2*p[i],l);
}
}
pair<long long,int> ans1={0,0};
long long ans=1e18;
for(int i=n-1;i>=0;i--){
ans=min(dp[i].first+ans1.first,ans);
if(ans1.second){
ans1.second--;
ans1.first+=p[i+1]-p[i];
ans1.first+=min(p[i],l-p[i])-min(p[i+1],l-p[i+1]);
}
else{
ans1.second=k-1;
ans1.first+=min(2*(l-p[i]),l);
}
}
ans=min(ans,ans1.first);
return ans;
}
# | 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... |