# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245790 | Nightlight | Safety (NOI18_safety) | C++14 | 68 ms | 5636 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |