Submission #470081

#TimeUsernameProblemLanguageResultExecution timeMemory
470081definitelynotmeeSafety (NOI18_safety)C++98
9 / 100
3 ms972 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; vector<ll> v(n); cin >> n >> h; 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] + offset <= last.ff){ //cout << 'a' << '\n'; 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 << "last = " << last.ff << ' ' << last.ss << '\n'; cout << "left: " ; for(int j : left) cout << j << ' '; cout << "\nright: "; for(int j : right) cout << j << ' '; cout << "\nresp(" << i <<") = " << resp << '\n'; cout << '\n';*/ } 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...