이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;
int main() {
int n, h;
cin >> n >> h;
priority_queue<ll> lq;
priority_queue<ll, vector<ll>, greater<ll> > hq;
ll off = 0;
ll val = 0;
for (int i = 0; i < n; i++) {
int e;
cin >> e;
if (i > 0) off += h;
else {
hq.push(e);
lq.push(e);
continue;
}
ll cut = lq.top() - off;
if (e <= cut) {
val += cut - e;
lq.push(e+off);
lq.push(e+off);
hq.push(lq.top() - off - off);
lq.pop();
} else {
if (e > hq.top() + off) val -= hq.top() + off - e;
hq.push(e-off);
hq.push(e-off);
lq.push(hq.top() + off + off);
hq.pop();
}
}
cout << val << "\n";
}
# | 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... |