Submission #1101897

#TimeUsernameProblemLanguageResultExecution timeMemory
1101897WarinchaiSafety (NOI18_safety)C++14
4 / 100
25 ms3960 KiB
#include<bits/stdc++.h> using namespace std; priority_queue<int,vector<int>,greater<int>>r; priority_queue<int>l; int ar[200005]; int lzl,lzr; 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; for(int i=1;i<=n;i++){ if(i!=1&&ar[i]<l.top()+lzl){ ans+=l.top()+lzl-ar[i]; l.push(ar[i]-lzl); l.push(ar[i]-lzl); r.push(l.top()+lzl-lzr); l.pop(); }else if(i!=1&&ar[i]>r.top()+lzr){ ans+=ar[i]-r.top()-lzr; r.push(ar[i]-lzr); r.push(ar[i]-lzr); l.push(r.top()+lzr-lzl); r.pop(); }else{ l.push(ar[i]-lzl); r.push(ar[i]-lzr); } lzl-=h; lzr+=h; } 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...