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;
typedef long long ll;
const ll INF = 1000000000000000006LL;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<ll> h(n);
for (int i = 0; i < n; i++) cin >> h[i];
vector<ll> w(n);
for (int i = 0; i < n; i++) cin >> w[i];
vector<ll> dp(n, INF);
dp[0] = 0;
for (int i = 1; i < n; i++) {
ll cost = 0;
for (int j = i - 1; j >= 0; j--) {
dp[i] = min(dp[i], dp[j] + cost + (h[i] - h[j]) * (h[i] - h[j]));
cost += w[j];
}
}
cout << dp[n - 1] << "\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... |