#include <bits/stdc++.h>
using namespace std;
const int N = 100'000 + 10;
int n;
int h[N], w[N];
int d[N];
long long f[N];
int32_t 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];
for (int i = 1; i <= n; ++i) d[i] = d[i - 1] + w[i];
memset(f, 40, sizeof f);
f[1] = 0;
for (int i = 1; i <= n; ++i) {
auto& ret = f[i];
for (int j = 1; j < i; ++j) ret = min(ret, f[j] + 1ll * (h[i] - h[j]) * (h[i] - h[j]) + d[i - 1] - d[j]);
}
cout << f[n] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1244 KB |
Output is correct |
4 |
Correct |
2 ms |
1116 KB |
Output is correct |
5 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3036 ms |
3212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1244 KB |
Output is correct |
4 |
Correct |
2 ms |
1116 KB |
Output is correct |
5 |
Correct |
2 ms |
1116 KB |
Output is correct |
6 |
Execution timed out |
3036 ms |
3212 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |