답안 #482706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482706 2021-10-26T05:56:36 Z mihai145 Safety (NOI18_safety) C++14
0 / 100
65 ms 12600 KB
//
// Created by Mihai145 on 10/25/2021.
//

#include <iostream>
#include <set>

using namespace std;

int N, H, x;
long long ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> H >> x;

    multiset<long long> lefts, rights;
    lefts.insert(x), rights.insert(x);

    for(int i = 1; i < N; i++) {
        cin >> x;

        long long shift = 1LL * i * H;
        long long lfb = *lefts.rbegin();
        long long lfb_val = lfb - shift;

        long long rb = *rights.begin();
        long long rb_val = rb + shift;

        if(x <= lfb_val) {
            ans += (lfb_val - x);
            lefts.insert(x + shift);
            lefts.insert(x + shift);
            lefts.erase(lefts.find(lfb));
            rights.insert(rb);
        } else if(x >= rb_val) {
            ans += (x - rb_val);
            rights.insert(x - shift);
            rights.insert(x - shift);
            rights.erase(rights.find(rb));
            lefts.insert(lfb);
        } else {
            lefts.insert(lfb);
            rights.insert(rb);
        }
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 12600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -