#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 |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3029 ms |
6632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Execution timed out |
3029 ms |
6632 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |