제출 #1166118

#제출 시각아이디문제언어결과실행 시간메모리
1166118spycoderytSafety (NOI18_safety)C++20
100 / 100
66 ms3684 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int32_t 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...