Submission #470092

#TimeUsernameProblemLanguageResultExecution timeMemory
470092definitelynotmeeSafety (NOI18_safety)C++17
100 / 100
239 ms20556 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]; multiset<ll,greater<ll>> left ={v[0]}; multiset<ll> right = {v[0]}; ll offset = 0; ll resp = 0; for(int i = 1; i < n; i++){ offset+=h; pll last = {*left.begin()-offset,*right.begin()+offset}; if(v[i]<= last.ff){ left.insert(v[i]+offset); left.insert(v[i]+offset); right.insert(*left.begin()-offset*2); left.erase(left.begin()); resp+=max(0ll,last.ff-v[i]); } else { right.insert(v[i]-offset); right.insert(v[i]-offset); left.insert(*right.begin() +2*offset); right.erase(right.begin()); 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...