Submission #203796

#TimeUsernameProblemLanguageResultExecution timeMemory
203796dennisstarSafety (NOI18_safety)C++17
100 / 100
163 ms5524 KiB
#include <bits/stdc++.h> #define em emplace using namespace std; typedef long long ll; priority_queue<ll> L, R; int N; ll H, S, A; int main() { cin>>N>>H; for (int i=1; i<=N; i++) { cin>>S; if (i==1) { L.em(S), R.em(-S); continue; } if (S<L.top()-H*(i-1)) A+=(L.top()-H*(i-1))-S, R.em(-L.top()+2*H*(i-1)), L.em(S+H*(i-1)), L.em(S+H*(i-1)), L.pop(); else if (S>-R.top()+H*(i-1)) A+=S+R.top()-H*(i-1), L.em(-R.top()+2*H*(i-1)), R.em(-S+H*(i-1)), R.em(-S+H*(i-1)), R.pop(); else L.em(S+H*(i-1)), R.em(-S+H*(i-1)); } cout<<A<<'\n'; return 0; }
#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...