Submission #318636

#TimeUsernameProblemLanguageResultExecution timeMemory
318636MetBSafety (NOI18_safety)C++14
100 / 100
123 ms7164 KiB
#include <bits/stdc++.h> #define N 2000001 using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; const ll INF = 1e18, MOD = 998244353, MOD2 = 1e6 + 3; ll s, e, h, n, a[N]; priority_queue<ll, vector<ll>> lwing; priority_queue<ll, vector<ll>, greater<ll>> rwing; ll solve (string testname) { lwing.push (a[0]); rwing.push (a[0]); ll l = 0, r = 0; ll ans = 0; for (int i = 1; i < n; i++) { l += h, r -= h; ll ltop = lwing.top () - l; ll rtop = rwing.top () - r; if (a[i] < ltop) { lwing.pop (); lwing.push (a[i] + l), lwing.push (a[i] + l); rwing.push (ltop + r); ans += abs (a[i] - ltop); } else if (rtop < a[i]) { rwing.pop (); rwing.push (a[i] + r), rwing.push (a[i] + r); lwing.push (rtop + l); ans += abs (a[i] - rtop); } else { lwing.push (a[i] + l); rwing.push (a[i] + r); } } return ans; } int main () { /*cin >> s >> e >> h; mt19937 rng; n = 300; while (s <= e) { string testname = "test_" + to_string (s++); ofstream fout (testname + ".in"); int lh = uniform_int_distribution<int>(h / 10, max ((int) 1e9, 10 * h))(rng); fout << n << '\n' << << '\n'; for (int i = 0; i < n; i++) { a[i] = uniform_int_distribution<int>(1, 1000000000)(rng); fout << a[i] << ' '; } fout << endl; fout.close (); }*/ cin >> n >> h; for (int i = 0; i < n; i++) { cin >> a[i]; } cout << solve (""); }
#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...