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;
long long inf = 2e18;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
long long arr[n];
for(long long &i : arr){
cin >> i;
}
long long w[n];
for(long long &i : w){
cin >> i;
}
long long dp[n];
dp[0]=0;
dp[1]=(arr[0]-arr[1])*(arr[0]-arr[1]);
for(long long i = 2;i<n;i++){
long long sm = 0;
dp[i]=inf;
for(long long j = i-1;j>=0;j--){
dp[i]=min(dp[i],dp[j]+sm+(arr[i]-arr[j])*(arr[i]-arr[j]));
sm+=w[j];
}
}
cout << dp[n-1];
return 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... |