#include <bits/stdc++.h>
using namespace std;
#define forw(i,a,b) for(ll i=a;i<=b;i++)
#define forb(i,a,b) for(ll i=a;i>=b;i--)
typedef long long int ll;
ll res,n,h[100005],w[100005],max1[100005],pre[100005],dp[100005];
void sub1()
{
for (int i=2;i<=n;i++)
{
max1[i]=1e18;
res=0;
for (int j=i-1;1;j--)
{
ll p=(h[i]-h[j])*(h[i]-h[j])+res+max1[j];
if (p<max1[i]) max1[i]=p;
res+=w[j];
}
}
cout<<max1[n];
}
int main()
{
//freopen("test.INP","r",stdin);
//freopen("test.OUT","w",stdout);
cin>>n;
for (int i=1;i<=n;i++)
cin>>h[i];
for (int i=1;i<=n;i++)
cin>>w[i];
sub1();
//else sub2();
//sub2();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3069 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3064 ms |
1732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3069 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |