이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, h, x, i;
ll miny = 0, lzl, lzr;
priority_queue<ll> l;
priority_queue<ll, vector<ll>, greater<ll>> r;
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> h;
for(i=0;i<n;i++) {
cin >> x;
if(l.empty() || r.empty()) {
l.push(x); r.push(x);
} else {
if(x <= l.top()+lzl) {
miny += l.top() + lzl - x;
l.push(x-lzl); l.push(x-lzl); r.push(l.top()+lzl-lzr); l.pop();
} else if(r.top() + lzr <= x) {
miny += x - (r.top() + lzr);
r.push(x-lzr); r.push(x-lzr); l.push(r.top()+lzr-lzl); r.pop();
} else {
l.push(x-lzl); r.push(x-lzr);
}
}
lzl -= h; lzr += h;
}
cout << miny;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |