Submission #957243

#TimeUsernameProblemLanguageResultExecution timeMemory
957243smjun04Safety (NOI18_safety)C++17
18 / 100
38 ms5424 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL constexpr bool local = true; #else constexpr bool local = false; #endif #define FASTIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define ll long long #define debug if constexpr (local) std::cout #define endl '\n' int main() { FASTIO int n, h; cin >> n >> h; vector<ll> v(n); for (int i = 0; i < n; i++) cin >> v[i]; ll res = 0; priority_queue<int> l; priority_queue<int, vector<int>, greater<int>> r; l.push(v[0]); r.push(v[0]); for (int i = 1; i < n; i++){ int lopt = l.top() - i*h, ropt = r.top() + i*h; if (v[i] < lopt){ res += lopt - v[i]; r.push(lopt-i*h); l.push(v[i]+i*h); l.push(v[i]+i*h); l.pop(); } else if (ropt < v[i]){ res += v[i] - ropt; l.push(ropt+i*h); r.push(v[i]-i*h); r.push(v[i]-i*h); r.pop(); } else{ l.push(v[i]+i*h); r.push(v[i]-i*h); } } 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...