#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];
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];
for(int i=1;i<=n;i++)
pre[i]=pre[i-1]+w[i];
for(int i=1;i<=n;i++)
dp[i]=1e18;
dp[1]=0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
dp[j]=min(dp[j],dp[i]+(pre[j-1]-pre[i])+((h[j]-h[i])*(h[j]-h[i])));
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 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3099 ms |
3416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Execution timed out |
3099 ms |
3416 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |