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 ff first
#define ss second
#define pb push_back
#define int long long
const int N=3e5+5;
int h[N],w[N];
int dp[N];
signed main(){
int n;
cin>>n;
int k=0;
for(int i=1;i<=n;i++){
cin>>h[i];
}
for(int i=1;i<=n;i++){
cin>>w[i];
k+=w[i];
}
dp[1]=-w[1];
for(int i=2;i<=n;i++){
dp[i]=1e18;
}
for(int i=2;i<=n;i++){
for(int j=1;j<i;j++){
dp[i]=min(dp[i],dp[j]+(h[i]-h[j])*(h[i]-h[j])-w[i]);
}
}
cout<<dp[n]+k;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |