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 ln '\n'
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define int long long
const int inf = 2e18;
const int N = 1e5 + 7;
int h[N], w[N], n, ps[N], f[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++) cin >> h[i];
for(int i = 1; i <= n; i++) cin >> w[i], ps[i] = ps[i - 1] + w[i];
for(int i = 2; i <= n; i++) {
f[i] = inf;
for(int j = 1; j < i; j++) {
f[i] = min(f[i], f[j] + ps[i - 1] - ps[j] + (h[i] - h[j]) * (h[i] - h[j]));
}
}
cout << f[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... |