#include <bits/stdc++.h>
#define int long long
#define emb emplace_back
#define pii pair <int, int>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e18;
const int N = 1e5 + 5;
int n, h[N], w[N], pref[N], dp[N];
signed main(){
cin.tie(NULL)->sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) cin >> h[i];
for (int i = 1; i <= n; i++) cin >> w[i], pref[i] = pref[i - 1] + w[i];
dp[1] = 0;
for (int i = 2; i <= n; i++) dp[i] = inf;
for (int i = 2; i <= n; i++) {
for (int j = i - 1; j >= 1; j--) {
dp[i] = min(dp[i], dp[j] + pref[i - 1] - pref[j] + (h[i] - h[j]) * (h[i] - h[j]));
}
}
cout << dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |