//https://www.spoj.com/problems/EC_P/
//https://www.spoj.com/problems/tag/scc
#include <bits/stdc++.h>
#define F first
#define S second
#define I insert
#define LL long long
#define PB push_back
#define MP make_pair
const LL N=100005, mod=998244353;
using namespace std;
LL n, m, i, j, k, l, r, t, h[N], a[N], dp[N], sum;
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(i=0;i<n;i++)cin>>h[i];
for(i=0;i<n;i++)cin>>a[i];
for(i=1;i<n;i++){
sum=0;dp[i]=mod;
for(j=i-1;j>=0;j--){
dp[i]=min(dp[i],dp[j]+sum+(h[i]-h[j])*(h[i]-h[j]));
sum+=a[j];
}
}
cout<<dp[n-1]<<endl;
return 0;
}
// IIIIIIIII OOOOO A NN N EEEEEEEEEE
// I O O A A N N N E
// I O O A A N N N E
// I O O A A N N N E
// I O O AAAAAAAAA N N N EEEEEEEE
// I O O A A N N N E
// I O O A A N N N E
// I O O A A N N N E
// IIIIIIIII OOOOO A A N NN EEEEEEEEEE ___ KAPANADZE
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
3 ms |
616 KB |
Output is correct |
5 |
Correct |
4 ms |
680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3047 ms |
3916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
3 ms |
616 KB |
Output is correct |
5 |
Correct |
4 ms |
680 KB |
Output is correct |
6 |
Execution timed out |
3047 ms |
3916 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |