Submission #572475

#TimeUsernameProblemLanguageResultExecution timeMemory
572475MODDISafety (NOI18_safety)C++14
100 / 100
117 ms7024 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> const ll inf=1987654321987654321; int a,b; ll o[222222]; priority_queue<ll> l; priority_queue<ll,vector<ll>,greater<ll>> r; int main() { cin>>a>>b; for(int t=1;t<=a;t++) cin>>o[t]; ll ans=0; l.push(o[1]); r.push(o[1]); for(int t=2;t<=a;t++) { ll x=l.top()-(ll)(t-1)*b,y=r.top()+(ll)(t-1)*b; if(x<=o[t]&&o[t]<=y) { l.push(o[t]+(ll)(t-1)*b); r.push(o[t]-(ll)(t-1)*b); } else if(o[t]<x) { ans+=x-o[t]; l.push(o[t]+(ll)(t-1)*b); l.push(o[t]+(ll)(t-1)*b); r.push(x-(ll)(t-1)*b); l.pop(); } else { ans+=o[t]-y; r.push(o[t]-(ll)(t-1)*b); r.push(o[t]-(ll)(t-1)*b); l.push(y+(ll)(t-1)*b); r.pop(); } } cout<<ans<<endl; }
#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...