Submission #784316

#TimeUsernameProblemLanguageResultExecution timeMemory
78431612345678Safety (NOI18_safety)C++17
100 / 100
49 ms5508 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long ll n, h, lzl, lzr, s, ans; priority_queue<ll> l; priority_queue<ll, vector<ll>, greater<ll>> r; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>h; for (int i=1; i<=n; i++) { cin>>s; if (i>1&&s<l.top()+lzl) { l.push(s-lzl); l.push(s-lzl); ll tmp=l.top()+lzl; ans+=tmp-s; l.pop(); r.push(tmp-lzr); } else if (i>1&&s>r.top()+lzr) { r.push(s-lzr); r.push(s-lzr); ll tmp=r.top()+lzr; ans+=s-tmp; r.pop(); l.push(tmp-lzl); } else { l.push(s-lzl); r.push(s-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...