Submission #668424

#TimeUsernameProblemLanguageResultExecution timeMemory
668424600MihneaSafety (NOI18_safety)C++17
100 / 100
207 ms21108 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { #ifdef ONPC freopen ("input.txt", "r", stdin); #endif // ONPC #ifndef ONPC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif // ONPC int n, dmax, sol = 0, lazy = 0; cin >> n >> dmax; multiset<int> a, b; for (int i = 0; i < n; i++) { int x; cin >> x; if (i == 0) { a.insert(x); b.insert(x); continue; } lazy += dmax; auto ita = a.end(); ita--; if (x <= *ita - lazy) { sol += *ita - lazy - x; b.insert(*ita - lazy - lazy); a.erase(ita); a.insert(x + lazy); a.insert(x + lazy); } else { auto itb = b.begin(); if (x >= *itb + lazy) { sol += x - (*itb + lazy); a.insert(*itb + lazy + lazy); b.erase(itb); b.insert(x - lazy); b.insert(x - lazy); } else { a.insert(x + lazy); b.insert(x - lazy); } } } cout << sol << "\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...