Submission #231393

#TimeUsernameProblemLanguageResultExecution timeMemory
231393brcodeSafety (NOI18_safety)C++14
100 / 100
160 ms5528 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; long long ans; priority_queue<long long> l; priority_queue<long long,vector<long long>,greater<long long>> r; int main(){ long long n,k; cin>>n>>k; long long x; cin>>x; l.push(x); r.push(x); for(long long i=1;i<n;i++){ long long x; cin>>x; long long offset = 1LL*i*(k); long long lborder = l.top()-offset; long long rborder = r.top()+offset; if(x<lborder){ l.push(x+offset); l.push(x+offset); l.pop(); r.push(lborder-offset); ans+=abs(lborder-x); }else if(x>rborder){ r.push(x-offset); r.push(x-offset); r.pop(); l.push(rborder+offset); ans+=abs(rborder-x); }else{ l.push(x+offset); r.push(x-offset); } } 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...