Submission #470094

#TimeUsernameProblemLanguageResultExecution timeMemory
470094definitelynotmeeSafety (NOI18_safety)C++98
100 / 100
59 ms5100 KiB
#include<bits/stdc++.h> #define mp make_pair #define mt make_tuple #define ff first #define ss second using namespace std; template <typename T> using matrix = vector<vector<T>>; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll INFL = (1LL<<62)-1; const int INF = (1<<30)-1; const double EPS = 1e-7; const int MOD = 1e9 + 7; const int MAXN = 1e6+1; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; ll h; cin >> n >> h; vector<ll> v(n); for(int i = 0; i < n; i++) cin >> v[i]; priority_queue<ll> left; priority_queue<ll,vector<ll>,greater<ll>> right; left.push(v[0]); right.push(v[0]); ll offset = 0; ll resp = 0; for(int i = 1; i < n; i++){ offset+=h; pll last = {left.top()-offset,right.top()+offset}; if(v[i]<= last.ff){ left.push(v[i]+offset); left.push(v[i]+offset); right.push(left.top()-offset*2); left.pop(); resp+=max(0ll,last.ff-v[i]); } else { right.push(v[i]-offset); right.push(v[i]-offset); left.push(right.top() +2*offset); right.pop(); resp+=max(0ll,v[i]-last.ss); } } cout << resp << '\n'; 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...