Submission #553514

#TimeUsernameProblemLanguageResultExecution timeMemory
553514JomnoiSafety (NOI18_safety)C++17
100 / 100
236 ms21004 KiB
#include <bits/stdc++.h> #define DEBUG false using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, H, S; cin >> N >> H >> S; long long shift = 0, yMin = 0; multiset <long long> L, R; L.insert(S); R.insert(S); for(int i = 2; i <= N; i++) { cin >> S; shift += H; if(S < *L.rbegin() - shift) { yMin += (*L.rbegin() - shift) - S; L.insert(S + shift); L.insert(S + shift); R.insert(*L.rbegin() - 2 * shift); L.erase(L.lower_bound(*L.rbegin())); } else if(S > *R.begin() + shift) { yMin += S - (*R.begin() + shift); R.insert(S - shift); R.insert(S - shift); L.insert(*R.begin() + 2 * shift); R.erase(R.lower_bound(*R.begin())); } else { L.insert(S + shift); R.insert(S - shift); } } cout << yMin; 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...