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;
int n,i,j;
long long x,s[100001],h[100001],dp[100001];
int main()
{
cin>>n;
for (i=1;i<=n;i++)
cin>>h[i];
for (i=1;i<=n;i++)
{
cin>>x;
s[i]=s[i-1]+x;
dp[i]=100000000000000000;
}
dp[1]=0;
for (i=2;i<=n;i++)
for (j=1;j<i;j++)
dp[i]=min(dp[i],dp[j]+s[i-1]-s[j]+h[i]*h[i]+h[j]*h[j]-2*h[i]*h[j]);
cout<<dp[n]<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |