# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
245790 | Nightlight | Safety (NOI18_safety) | C++14 | 68 ms | 5636 KiB |
이 제출은 이전 버전의 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) {
# | 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... |