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;
#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll INF = 1e18;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> h(n + 1), w(n + 1);
for (int i = 1; i <= n; i += 1) {
cin >> h[i];
}
vector<ll> pref(n + 1, 0);
for (int i = 1; i <= n; i += 1) {
cin >> w[i];
pref[i] = pref[i - 1] + w[i];
}
vector<ll> dp(n + 1, INF);
dp[1] = 0;
for (int i = 2; i <= n; i += 1) {
for (int j = 1; j < i; j += 1) {
dp[i] = min(dp[i], h[i] * -2 * h[j] + (dp[j] + h[j] * h[j] - pref[j]));
}
dp[i] += pref[i - 1] + h[i] * h[i];
}
cout << dp[n] << endl;
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... |