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;
const int k_N = 1e5 + 3;
const long long k_Inf = 1e18;
int n;
long long h[k_N], w[k_N];
long long dp[k_N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; ++i)
cin >> h[i];
for(int i = 0; i < n; ++i)
cin >> w[i];
dp[n - 1] = 0;
for(int i = n - 2; i >= 0; --i){
dp[i] = k_Inf;
long long sum = 0;
for(int j = i + 1; j <= n - 1; ++j){
dp[i] = min(sum + (h[i] - h[j]) * (h[i] - h[j]) + dp[j], dp[i]);
sum += w[j];
}
}
cout << dp[0] << "\n";
}
/*
6
3 8 7 1 6 6
0 -1 9 1 2 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... |