Submission #113895

#TimeUsernameProblemLanguageResultExecution timeMemory
113895ckodserBuilding Bridges (CEOI17_building)C++14
30 / 100
3029 ms6632 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define ld long double #define F first #define S second #define pii pair<ll,ll> using namespace :: std; const ll mod=1e9+7; const ll maxn=1e5+500; const ll inf=1e18+900; vector<pii> vec; ll kojas(ll a,ll t){ return vec[a].F+vec[a].S*t; } ll kojas(pii e,ll t){ return e.F+e.S*t; } void addLine(ll x,ll v){ vec.pb(mp(x,v)); } ll find_min_aT(ll t){ ll ans=inf; for(auto e:vec){ ans=min(ans,kojas(e,t)); } return ans; } ll h[maxn]; ll w[maxn]; ll c[maxn]; ll dp[maxn]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll n,s=0; cin>>n; for(ll i=0;i<n;i++){ cin>>h[i]; } for(ll i=0;i<n;i++){ cin>>w[i]; s+=w[i]; } for(ll i=0;i<n;i++){ c[i]=-w[i]+h[i]*h[i]; if(0<i && i<n-1){ c[i]+=h[i]*h[i]; } } dp[0]=c[0]; addLine(dp[0],-2*h[0]); for(ll i=1;i<n;i++){ dp[i]=find_min_aT(h[i])+c[i]; addLine(dp[i],-2*h[i]); } cout<<dp[n-1]+s; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...