Submission #164936

#TimeUsernameProblemLanguageResultExecution timeMemory
164936gs18103Safety (NOI18_safety)C++14
100 / 100
70 ms3684 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; ll h; cin >> n >> h; priority_queue<ll> left; priority_queue<ll, vector<ll>, greater<ll>> right; ll ans = 0; int s; cin >> s; left.push(s); right.push(s); for (int i = 1; i < n; i++) { cin >> s; ll shift = i * h; ll left_border = left.top() - shift; ll right_border = right.top() + shift; if (s < left_border) { left.push(s + shift); left.push(s + shift); left.pop(); right.push(left_border - shift); ans += abs(s - left_border); } else if (s > right_border) { right.push(s - shift); right.push(s - shift); right.pop(); left.push(right_border + shift); ans += abs(s - right_border); } else { left.push(s + shift); right.push(s - shift); } } cout << ans; 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...