Submission #524071

#TimeUsernameProblemLanguageResultExecution timeMemory
524071DanerZeinDischarging (NOI20_discharging)C++14
100 / 100
385 ms17932 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N=1e6+10; const ll MAX=1e9; struct line{ ll m,b; line(ll mm,ll bb){ m=mm; b=bb; } ll eval(ll x){ return m*x+b; } long double intersect(line l){ return (long double)(b-l.b)/(l.m-m); } /* ll intersect(line l){ ll le=1; ll ri=1; while(eval(ri)>l.eval(ri)){ le=ri; ri*=2; } while(ri>le){ ll mid=(le+ri)/2; if(eval(mid)<=l.eval(mid)) ri=mid; else le=mid+1; } return ri; }*/ }; ll val[MAX_N]; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>val[i]; val[i]=max(val[i],val[i-1]); } deque<line> dq; dq.push_front({MAX,MAX}); ll ans=0; for(int i=1;i<=n;i++){ int t=dq.size(); line nl={(n-i+1),ans}; while(t>=2 && nl.intersect(dq[t-2])<=dq[t-1].intersect(dq[t-2])){ dq.pop_back(); t--; } dq.push_back(nl); while(dq.size()>=2 && dq[0].eval(val[i])>=dq[1].eval(val[i])) dq.pop_front(); ans=dq.front().eval(val[i]); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...