Submission #1166116

#TimeUsernameProblemLanguageResultExecution timeMemory
1166116spycoderytSafety (NOI18_safety)C++20
4 / 100
44 ms1976 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n,h,x,ans=0; cin >> n >> h; priority_queue<int> lq; priority_queue<int,vector<int>,greater<int> > rq; for(int i = 0;i<n;i++) { cin >> x; if(i==0){ lq.push(x); rq.push(x); continue; } int range = i * h; if(x + range < lq.top()) { lq.push(x+range); ans += abs(lq.top() - (x+range)); lq.push(x+range); rq.push(lq.top() - 2 * range); lq.pop(); } else if (x - range > rq.top()) { rq.push(x-range); ans += abs(rq.top() - (x - range)); rq.push(x-range); lq.push(rq.top() + 2 * range); rq.pop(); } else { lq.push(x+range); rq.push(x-range); } } cout<<ans; }
#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...