Submission #635659

#TimeUsernameProblemLanguageResultExecution timeMemory
635659PoonYaPatSafety (NOI18_safety)C++14
49 / 100
43 ms3748 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n,h,x; ll ymin, shift; priority_queue<int> lsq; priority_queue<int, vector<int>, greater<int>> rsq; //fake value (has to adjust with shift) int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>h>>x; lsq.push(x); rsq.push(x); for (int i=1; i<n; ++i) { cin>>x; shift+=h; ll l=lsq.top()-shift, r=rsq.top()+shift; //real value if (x<=l) { lsq.push(x+shift); lsq.push(x+shift); rsq.push(lsq.top()-2*shift); lsq.pop(); ymin+=(l-x); } else if (x>=r) { rsq.push(x-shift); rsq.push(x-shift); lsq.push(rsq.top()+2*shift); rsq.pop(); ymin+=(x-r); } else { lsq.push(x+shift); rsq.push(x-shift); } } cout<<ymin; }
#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...