Submission #70558

#TimeUsernameProblemLanguageResultExecution timeMemory
70558mr_bananaBoxes with souvenirs (IOI15_boxes)C++17
20 / 100
2 ms404 KiB
#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 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...