Submission #945918

#TimeUsernameProblemLanguageResultExecution timeMemory
945918WarinchaiSafety (NOI18_safety)C++14
4 / 100
26 ms3776 KiB
#include<bits/stdc++.h> using namespace std; int ar[200005]; priority_queue<int>pql; priority_queue<int,vector<int>,greater<int>>pqr; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,h;cin>>n>>h; for(int i=1;i<=n;i++)cin>>ar[i]; int ans=0; int lzl=0; int lzr=0; for(int i=1;i<=n;i++){ if(i!=1&&(ar[i]<pql.top()+lzl)){ ans+=pql.top()+lzl-ar[i]; pql.push(ar[i]-lzl); pql.push(ar[i]-lzl); pqr.push(pql.top()+lzl-lzr); pql.pop(); }else if(i!=1&&(ar[i]>pqr.top()+lzr)){ ans+=ar[i]-(pqr.top()+lzr); pqr.push(ar[i]-lzr); pqr.push(ar[i]-lzr); pql.push(pqr.top()+lzr-lzl); pqr.pop(); }else{ pql.push(ar[i]-lzl); pqr.push(ar[i]-lzr); } lzl-=h; lzr+=h; ///cout<<ans<<" "<<pql.top()+lzl<<' '<<pqr.top()+lzr<<"\n"; } cout<<ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...