Submission #565911

# Submission time Handle Problem Language Result Execution time Memory
565911 2022-05-21T14:13:40 Z hoanghq2004 Safety (NOI18_safety) C++14
100 / 100
75 ms 5520 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 2e5 + 10;

int n, h;
priority_queue <long long> L, R;

int main() {
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> h;
    long long x, delta = 0;
    cin >> x;
    delta += x - h;
    L.push(x - 1LL * h * n), R.push(- x - 1LL * h * n);
    for (int i = 2; i <= n; ++i) {
        cin >> x;
        delta += x - 1LL * h * i;
        long long add = 1LL * h * (n - i + 1);
        if (L.top() + add <= x && x <= - R.top() - add) {
            L.push(x - add), R.push(- x - add);
        } else if (x < L.top() + add) {
            L.push(x - add), L.push(x - add);
            long long y = L.top() + add * 2;
            L.pop();
            R.push(- y);
        } else {
            R.push(- x - add), R.push(- x - add);
            long long y = - R.top() - add * 2;
            R.pop();
            L.push(y);
        }
    }
    while (L.size()) delta -= L.top(), L.pop();
    cout << delta;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 4736 KB Output is correct
2 Correct 70 ms 5152 KB Output is correct
3 Correct 70 ms 5348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 516 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 392 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 316 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 2 ms 516 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 2 ms 392 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 51 ms 4736 KB Output is correct
20 Correct 70 ms 5152 KB Output is correct
21 Correct 70 ms 5348 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 316 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 2 ms 516 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 392 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 75 ms 5520 KB Output is correct
51 Correct 61 ms 5108 KB Output is correct
52 Correct 36 ms 5084 KB Output is correct
53 Correct 45 ms 5248 KB Output is correct
54 Correct 57 ms 5220 KB Output is correct
55 Correct 36 ms 5072 KB Output is correct
56 Correct 41 ms 5152 KB Output is correct
57 Correct 38 ms 5096 KB Output is correct
58 Correct 35 ms 4464 KB Output is correct
59 Correct 44 ms 5056 KB Output is correct