답안 #482703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482703 2021-10-26T05:52:32 Z mihai145 Safety (NOI18_safety) C++14
0 / 100
74 ms 6824 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<int> 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(lfb);
            rights.insert(rb);
        } else if(x >= rb_val) {
            ans += (x - rb_val);
            rights.insert(x - shift);
            rights.insert(x - shift);
            rights.erase(rb);
            lefts.insert(lfb);
        } else {
            lefts.insert(x + shift);
            rights.insert(x - shift);
        }
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Runtime error 1 ms 444 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 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 74 ms 6824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Runtime error 1 ms 444 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Runtime error 1 ms 444 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Runtime error 1 ms 444 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Runtime error 1 ms 444 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Runtime error 1 ms 444 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -