Submission #1012839

#TimeUsernameProblemLanguageResultExecution timeMemory
1012839idiotcomputerSafety (NOI18_safety)C++11
100 / 100
42 ms5516 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int #define sz size int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; ll h; cin >> n >> h; priority_queue<ll> l; priority_queue<ll,vector<ll>,greater<ll>> r; ll a; ll ans = 0; cin >> a; l.push(a); r.push(a); ll diff; for (int i = 1; i < n; i++){ cin >> a; diff = h*i; if (a+diff < l.top()){ l.push(a+diff); l.push(a+diff); ans += abs(l.top()-a-diff); r.push(l.top()-diff*2); l.pop(); } else if (a-diff > r.top()){ r.push(a-diff); r.push(a-diff); ans += abs(a-diff-r.top()); l.push(r.top()+2*diff); r.pop(); } else { l.push(a+diff); r.push(a-diff); } } cout << ans << "\n"; }
#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...