이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
ll N, D, ans = 0;
cin >> N >> D;
ll Loff = 0, Roff = 0;
priority_queue<ll> L;
priority_queue<ll, vector<ll>, greater<ll>> R;
for (int i = 1; i <= N; ++i) {
ll n;
cin >> n;
Loff -= D; Roff += D;
if (L.empty() || n <= R.top() + Roff) {
if (!L.empty() && n < L.top() + Loff) ans += (L.top() + Loff) - n;
L.push(n - Loff);
L.push(n - Loff);
}
else {
ans += n - (R.top() + Roff);
R.push(n - Roff);
R.push(n - Roff);
}
while (L.size() > R.size()) {
R.push(L.top() + Loff - Roff);
L.pop();
}
while (R.size() > L.size()) {
L.push(R.top() + Roff - Loff);
R.pop();
}
}
cout << ans;
return 0;
}
| # | 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... |