#include <bits/stdc++.h>
using namespace std;
const int k_N = 1e5 + 3;
const long long k_Inf = 1e18;
int n;
long long h[k_N], w[k_N];
long long dp[k_N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; ++i)
cin >> h[i];
for(int i = 0; i < n; ++i)
cin >> w[i];
dp[n - 1] = 0;
for(int i = n - 2; i >= 0; --i){
dp[i] = k_Inf;
long long sum = 0;
for(int j = i + 1; j <= n - 1; ++j){
dp[i] = min(sum + (h[i] - h[j]) * (h[i] - h[j]) + dp[j], dp[i]);
sum += w[j];
}
}
cout << dp[0] << "\n";
}
/*
6
3 8 7 1 6 6
0 -1 9 1 2 0
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3036 ms |
2596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
3036 ms |
2596 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |