This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://www.spoj.com/problems/EC_P/
//https://www.spoj.com/problems/tag/scc
#include <bits/stdc++.h>
#define F first
#define S second
#define I insert
#define LL long long
#define PB push_back
#define MP make_pair
const LL N=100005, mod=998244353;
using namespace std;
LL n, m, i, j, k, l, r, t, h[N], a[N], dp[N], sum;
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(i=0;i<n;i++)cin>>h[i];
for(i=0;i<n;i++)cin>>a[i];
for(i=1;i<n;i++){
sum=0;dp[i]=mod;
for(j=i-1;j>=0;j--){
dp[i]=min(dp[i],dp[j]+sum+(h[i]-h[j])*(h[i]-h[j]));
sum+=a[j];
}
}
cout<<dp[n-1]<<endl;
return 0;
}
// IIIIIIIII OOOOO A NN N EEEEEEEEEE
// I O O A A N N N E
// I O O A A N N N E
// I O O A A N N N E
// I O O AAAAAAAAA N N N EEEEEEEE
// I O O A A N N N E
// I O O A A N N N E
// I O O A A N N N E
// IIIIIIIII OOOOO A A N NN EEEEEEEEEE ___ KAPANADZE
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |