Submission #674087

#TimeUsernameProblemLanguageResultExecution timeMemory
674087jiahngSafety (NOI18_safety)C++14
100 / 100
49 ms5484 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<ll,ll> pi; typedef vector <int> vi; typedef vector <pi> vpi; typedef pair<pi,ll> pii; typedef set <ll> si; typedef long double ld; #define f first #define s second #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0) #define maxn 1000001 #define INF (ll)1e13 #define DEBUG 0 #define MOD 1000000007 //#define getchar_unlocked _getchar_nolock int N,H,t; priority_queue <int> leftpq; priority_queue <int,vector <int>, greater <int> > rightpq; int leftoffset = 0, rightoffset = 0; int ans = 0; int32_t main(){ fast; cin >> N >> H; cin >> t; leftpq.push(t-H); rightpq.push(t+H); FOR(i,2,N){ cin >> t; if (t <= leftpq.top() + leftoffset) { ans += abs(t - (leftpq.top() + leftoffset)); leftpq.push(t-leftoffset); leftpq.push(t-leftoffset); rightpq.push(leftpq.top()+leftoffset-rightoffset); leftpq.pop(); }else{ if (t >= rightpq.top() + rightoffset) ans += abs(t - (rightpq.top() + rightoffset)); rightpq.push(t-rightoffset); rightpq.push(t-rightoffset); leftpq.push(rightpq.top()+rightoffset-leftoffset); rightpq.pop(); } leftoffset -= H; rightoffset += H; //cout << ans << ' '; } cout << ans; }
#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...