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