#include <bits/stdc++.h>
using namespace std;
long long inf = 2e18;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
long long arr[n];
for(long long &i : arr){
cin >> i;
}
long long w[n];
for(long long &i : w){
cin >> i;
}
long long dp[n];
dp[0]=0;
dp[1]=arr[0]*arr[0]+arr[1]*arr[1]-2*arr[0]*arr[1];
long long pref[n];
pref[0]=w[0];
for(int i = 1;i<n;i++){
pref[i]=pref[i-1]+w[i];
}
for(long long i = 2;i<n;i++){
long long sm = 0;
dp[i]=inf;
for(long long j = i-1;j>=0;j--){
dp[i]=min(dp[i],dp[j]+pref[i-1]-pref[j]+arr[i]*arr[i]+arr[j]*arr[j]-2*arr[i]*arr[j]);
sm+=w[j];
}
}
cout << dp[n-1];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3070 ms |
3408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Execution timed out |
3070 ms |
3408 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |