Submission #482703

#TimeUsernameProblemLanguageResultExecution timeMemory
482703mihai145Safety (NOI18_safety)C++14
0 / 100
74 ms6824 KiB
// // Created by Mihai145 on 10/25/2021. // #include <iostream> #include <set> using namespace std; int N, H, x; long long ans; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> H >> x; multiset<int> lefts, rights; lefts.insert(x), rights.insert(x); for(int i = 1; i < N; i++) { cin >> x; long long shift = 1LL * i * H; long long lfb = *lefts.rbegin(); long long lfb_val = lfb - shift; long long rb = *rights.begin(); long long rb_val = rb + shift; if(x <= lfb_val) { ans += (lfb_val - x); lefts.insert(x + shift); lefts.insert(x + shift); lefts.erase(lfb); rights.insert(rb); } else if(x >= rb_val) { ans += (x - rb_val); rights.insert(x - shift); rights.insert(x - shift); rights.erase(rb); lefts.insert(lfb); } else { lefts.insert(x + shift); rights.insert(x - shift); } } cout << ans << '\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...