제출 #788218

#제출 시각아이디문제언어결과실행 시간메모리
788218Charizard2021Safety (NOI18_safety)C++17
100 / 100
79 ms5408 KiB
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, h;
    cin >> n >> h;
    long long val1 = 0;
    long long val2 = 0;
    long long ans = 0;
    long long cur = -1e18;
    priority_queue<long long> L, R;
    for (int i = 1; i <= n; ++i) {
        long long x;
        cin >> x;
        if (x >= cur) {
            R.push(-x + val1);
            R.push(-x + val1);
            L.push(-R.top() + val1 - val2);
            R.pop();
            ans += x - L.top() - val2;
        }
        else {
            L.push(x - val2);
            L.push(x - val2);
            R.push(-L.top() - val2 + val1);
            L.pop();
            ans += -R.top() + val1 - x;
        }
        val2 -= h;
        val1 += h;
        cur = L.top() + val2;
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...