이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N;
long long A[100005];
long long ans;
priority_queue<long long, vector<long long>> L;
priority_queue<long long, vector<long long>, greater<long long>> R;
long long H, now, SL, SR;
int main() {
ios_base::sync_with_stdio(0);
cin >> N >> H;
cin >> now;
L.push(now);
R.push(now);
for(int i = 2; i <= N; i++) {
cin >> now;
SL += H;//shift kiri dan kanan by H
SR -= H;
long long Lnow = L.top() - SL;
long long Rnow = R.top() - SR;
// cout << Lnow << " " << Rnow << "\n";
if(now < Lnow) {
L.pop();//buang dari kiri masukin ke kanan
R.push(Lnow + SR);
L.push(now + SL);
L.push(now + SL);
ans += abs(now - Lnow);
}else if(now > Rnow) {
R.pop();
L.push(Rnow + SL);
R.push(now + SR);
R.push(now + SR);
ans += abs(now - Rnow);
}else {
L.push(now + SL);
R.push(now + SR);
}
}
cout << ans << "\n";
cin >> 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... |