#include <iostream>
using namespace std;
#define ll long long
const int N=1e5+100;
ll dp[N],a[N],pre[N],h[N],w[N];
ll cost(int i,int j)
{
return ((h[i]-h[j])*(h[i]-h[j]));
}
void solve()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>h[i];
for(int i=1;i<=n;i++)
{
cin>>w[i];
pre[i]=pre[i-1]+w[i];
}
for(int i=1;i<=n;i++)
dp[i]=1e18;
dp[1]=pre[n];
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
dp[j]=min(dp[j],dp[i]-w[j]+cost(i,j));
cout<<dp[n];
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int t=1;
while(t--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3040 ms |
4444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |