#include<bits/stdc++.h>
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define pp pair<ll, ll>
#define inf 1000000000000000
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
ll Wsum = 0;
vi h(n);
rep(i,n){
cin >> h[i];
}
vi w(n);
rep(i,n){
cin >> w[i];
Wsum += w[i];
}
vi dp(n, inf);
dp[0] = -w[0];
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
dp[i] = min(dp[i], dp[j] + (h[i] - h[j])*(h[i] - h[j]) - w[i]);
}
}
cout << dp[n-1] + Wsum << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3017 ms |
3672 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Execution timed out |
3017 ms |
3672 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |