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>
using namespace std;
#define ll long long
#define fs first
#define sc second
#define N 10000010
#define pb push_back
ll dp[1010][1010],a[N],length,k;
void selfmin(ll&u,ll v)
{
u=min(u,v);
}
ll get(int l,int r)
{
if(l>r)
return 0;
if(dp[l][r]!=-1)
return dp[l][r];
ll res=1e18;
for(int i=l;i<=r;i++)
if(i-l+1<=k)
selfmin(res,a[i]+min(a[i],length-a[i])+get(i+1,r));
for(int i=r;i>=l;i--)
if(r-i+1<=k)
selfmin(res,length-a[i]+min(a[i],length-a[i])+get(l,i-1));
return(dp[l][r]=res);
}
ll delivery(int n,int cc,int l,int mang[])
{
length=l;
k=cc;
for(int i=0;i<n;i++)
a[i]=mang[i];
memset(dp,-1,sizeof(dp));
return get(0,n-1);
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(NULL);
// cout.tie(NULL);
int n,k,l;
cin>>n>>k>>l;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
cout<<delivery(n,k,l,a);
return 0;
}
#endif // SKY
# | 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... |