Submission #714502

#TimeUsernameProblemLanguageResultExecution timeMemory
714502Spade1Safety (NOI18_safety)C++14
100 / 100
49 ms5484 KiB
#include<bits/stdc++.h> #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX using namespace std; priority_queue<ll> L, R; ll offset_l, offset_r, ans, pos = -1e18; void solve() { ll n, h; cin >> n >> h; for (int i = 1; i <= n; ++i) { ll a; cin >> a; offset_l -= h; offset_r += h; pos -= h; if (a >= pos) { R.push(-a+offset_r); R.push(-a+offset_r); L.push(-R.top()+offset_r-offset_l); R.pop(); ans += a-L.top()-offset_l; } else { L.push(a-offset_l); L.push(a-offset_l); R.push(-L.top()-offset_l+offset_r); L.pop(); ans += -R.top()+offset_r-a; } pos = L.top()+offset_l; } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } } /* 6 1 2 10 0 2 4 3 */
#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...