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<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int m[10000005];
ll dp1[10000005], dp2[10000005];
ll delivery(int N, int K, int L, int *positions)
{
for(int i=N ; i>0 ; i--) m[i]=positions[i-1];
for(int i=1 ; i<=N ; i++)
{
if(i<K) dp1[i]=m[i]+min(m[i],L-m[i]);
else dp1[i]=dp1[i-K]+m[i]+min(m[i],L-m[i]);
}
for(int i=N ; i>=1 ; i--)
{
if(N-i<K) dp2[i]=(L-m[i])+min(m[i],L-m[i]);
else dp2[i]=dp2[i+K]+(L-m[i])+min(m[i],L-m[i]);
}
ll res=dp1[0]+dp2[1];
for(int i=1 ; i<=N ; i++) res=min(res,dp1[i]+dp2[i+1]);
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... |