This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1e9+7;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t z;
const int mxn = 2e5+5;
int n;
ll h[mxn];
ll w[mxn];
ll dp[mxn];
ll pref[mxn];
ll p(ll a){
return a*a;
}
void solve(){
cin >> n;
fr(i, 0, n){
cin >> h[i];
}
fr(i, 0, n){
cin >> w[i];
}
pref[0] = w[0];
fr(i, 1, n){
pref[i] = pref[i-1]+w[i];
}
dp[0] = 0;
fr(i, 1, n){
dp[i] = inf;
fr(j, 0, i){
dp[i] = min(dp[i], dp[j] + (pref[i] - pref[j] - w[i]) + p(h[i]-h[j]));
}
}
cout<<dp[n-1]<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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... |