Submission #1000720

#TimeUsernameProblemLanguageResultExecution timeMemory
1000720vjudge1Safety (NOI18_safety)C++17
100 / 100
165 ms22548 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define int ll int a[200100]; void solve(){ int n, h; cin>>n>>h; for(int i=1; i<=n; i++){ cin>>a[i]; } multiset<ll> ql, qr; ql.insert(a[1]); qr.insert(a[1]); ll ans = 0; for(int i=2; i<=n; i++){ ll add = h * (i - 1); ll l=*ql.rbegin()-add, r=*qr.begin()+add; ll t = a[i]; if(l <= t and t <= r){ ql.insert(t+add); qr.insert(t-add); } else if(l > t){ ans += l-t; qr.insert(l-add); ql.erase(ql.find(l + add)); ql.insert(t+add); ql.insert(t+add); } else if(r < t){ ans += t - r; ql.insert(r+add); qr.erase(qr.find(r - add)); qr.insert(t-add); qr.insert(t-add); } } cout<<ans<<'\n'; } signed main(){ 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...