#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n;
cin>>n;
int a[n+3], b[n+3], pref[n+3];
for(int i=1;i<=n;i++){
cin>>a[i];
}
pref[0] = 0;
for(int i= 1;i<=n;i++){
cin>>b[i];
pref[i] = pref[i-1] + b[i];
}
int dp[n+3];
dp[1] = 0;
for(int i=2;i<=n;i++){
dp[i] = INF;
for(int j= 1;j<i;j++){
dp[i] = min(dp[j] + ((a[i]-a[j])*(a[i]-a[j])) + (pref[i-1]-pref[j]), dp[i]);
}
}
cout<<dp[n]<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
3244 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Execution timed out |
3068 ms |
3244 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |