이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pq_max = priority_queue<ll>;
using pq_min = priority_queue<ll, vector<ll>, greater<ll>>;
pq_max heap1;
pq_min heap2;
ll min_val = 0;
void add(int x, ll shift)
{
if(x + shift >= heap1.top() && x - shift <= heap2.top())
{
heap1.push(x + shift);
heap2.push(x - shift);
return;
}
if(x + shift < heap1.top())
{
heap1.push(x + shift);
heap1.push(x + shift);
ll out = heap1.top();
heap1.pop();
min_val += out - (x + shift);
heap2.push(out - 2 * shift);
}
else if(x - shift > heap2.top())
{
heap2.push(x - shift);
heap2.push(x - shift);
ll out = heap2.top();
heap2.pop();
min_val += (x-shift) - out;
heap1.push(out + 2 * shift);
}
else assert(0);
}
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false); cin.tie(0);
int i, x, n, H;
cin >> n >> H;
cin >> x;
heap1.push(x);
heap2.push(x);
for(i=2; i<=n; ++i)
{
cin >> x;
add(x, (ll) H * (i-1));
}
cout << min_val << '\n';
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... |