Submission #969910

#TimeUsernameProblemLanguageResultExecution timeMemory
969910VMaksimoski008Safety (NOI18_safety)C++17
100 / 100
82 ms5476 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int32_t main() { ll n, h, ans = 0; cin >> n >> h; priority_queue<ll> L; priority_queue<ll, vector<ll>, greater<ll> > R; for(int i=0; i<n; i++) { ll x; cin >> x; if(!i) { L.push(x); R.push(x); continue; } ll range = i * h; if(x + range < L.top()) { L.push(x + range); ans += L.top() - (x + range); L.push(x + range); R.push(L.top() - 2 * range); L.pop(); } else if(x - range > R.top()) { R.push(x - range); ans += (x - range) - R.top(); R.push(x - range); L.push(R.top() + 2 * range); R.pop(); } else { L.push(x + range); R.push(x - range); } } 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...