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<stdio.h>
#define INF 999999999999999LL
int n;
long long int m;
long long int a[100100];
long long int b[100100];
long long int c[100100];
long long int d[100100];
long long int dp[3010][3010];
long long int stp;
int main(){
// freopen("input.txt","r",stdin);
int i,j;
scanf("%d%lld",&n,&m);
dp[0][0]=m;
for(i=1;i<=n;i++){
dp[0][i]=INF;
}
stp=INF;
for(i=0;i<n;i++){
scanf("%lld%lld%lld%lld",&a[i],&b[i],&c[i],&d[i]);
if(stp>b[i]+c[i])stp=b[i]+c[i];
for(j=0;j<n;j++){
dp[i+1][j]=dp[i][j]+a[i]+b[i];
if(dp[i+1][j]>dp[i][j+1]+a[i]+d[i])dp[i+1][j]=dp[i][j+1]+a[i]+d[i];
if(j!=0&&dp[i+1][j]>dp[i][j-1]+b[i]+c[i])dp[i+1][j]=dp[i][j-1]+b[i]+c[i];
if(j!=0&&dp[i+1][j]>dp[i][j]+c[i]+d[i])dp[i+1][j]=dp[i][j]+c[i]+d[i];
if(j!=0&&dp[i+1][j]>dp[i+1][j-1]+stp)dp[i+1][j]=dp[i+1][j-1]+stp;
}
dp[i][n]=INF;
for(j=0;j<n;j++){
dp[i+1][j]+=m*(j*2+1);
}
stp+=2*m;
}
printf("%lld",dp[n][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... |