Submission #520673

#TimeUsernameProblemLanguageResultExecution timeMemory
520673two_sidesSafety (NOI18_safety)C++17
100 / 100
52 ms5544 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; priority_queue<ll,vector<ll>,less<ll>> lef; priority_queue<ll,vector<ll>,greater<ll>> rig; int main() { cin.tie(0)->sync_with_stdio(0); int n; ll h, x, res = 0; cin >> n >> h >> x; lef.push(x); rig.push(x); for (int i = 1; i < n; i++) { ll d = h * i; cin >> x; ll l = lef.top() - d; ll r = rig.top() + d; if (x < l) { lef.push(x + d); lef.push(x + d); lef.pop(); rig.push(l - d); res += l - x; } else if (x > r) { rig.push(x - d); rig.push(x - d); rig.pop(); lef.push(r + d); res += x - r; } else { lef.push(x + d); rig.push(x - d); } } cout << res; }
#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...