#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
const int N=1e5+5;
int n,m,T,k,dp[N],h[N],w[N],pref[N];
void test_case() {
cin>>n;
for (int i=1; i<=n; i++) cin>>h[i];
for (int i=1; i<=n; i++) {
cin>>w[i];
pref[i]=pref[i-1]+w[i];
}
dp[1]=0;
for (int i=2; i<=n; i++) {
dp[i]=1e18;
for (int j=1; j<i; j++) {
dp[i]=min(dp[i],dp[j]+pref[i-1]-pref[j]+(h[i]-h[j])*(h[i]-h[j]));
}
}
cout<<dp[n]<<endl;
}
main () {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
T=1;
while (T--) test_case();
}
Compilation message (stderr)
building.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
1 | #pragma GCC diagnostic warning "-std=c++11"
| ^~~~~~~~~~~~
building.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main () {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |