Submission #141529

#TimeUsernameProblemLanguageResultExecution timeMemory
141529meatrowSafety (NOI18_safety)C++17
18 / 100
68 ms3676 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //#pragma GCC optimize ("unroll-loops") #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, 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; int left_border = left.top() - shift; int right_border = right.top() + shift; if (s < left_border) { left.push(s + shift); left.push(s + shift); right.push(left.top() - 2 * shift); left.pop(); ans += abs(s - right.top() - shift); } else if (s > right_border) { right.push(s - shift); right.push(s - shift); left.push(right.top() + 2 * shift); right.pop(); ans += abs(s - left.top() + shift); } 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...