답안 #141529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141529 2019-08-08T10:19:40 Z meatrow Safety (NOI18_safety) C++17
18 / 100
68 ms 3676 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, h;
    cin >> n >> h;
    priority_queue<ll> left;
    priority_queue<ll, vector<ll>, greater<ll>> right;
    ll ans = 0;
    int s;
    cin >> s;
    left.push(s);
    right.push(s);
    for (int i = 1; i < n; i++) {
        cin >> s;
        ll shift = i * h;
        int left_border = left.top() - shift;
        int right_border = right.top() +  shift;
        if (s < left_border) {
            left.push(s + shift);
            left.push(s + shift);
            right.push(left.top() - 2 * shift);
            left.pop();
            ans += abs(s - right.top() - shift);
        } else if (s > right_border) {
            right.push(s - shift);
            right.push(s - shift);
            left.push(right.top() + 2 * shift);
            right.pop();
            ans += abs(s - left.top() + shift);
        } else {
            left.push(s + shift);
            right.push(s - shift);
        }
    }
    cout << ans;
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 3588 KB Output is correct
2 Correct 67 ms 3676 KB Output is correct
3 Correct 68 ms 3660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 3 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -