이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |