Submission #499806

# Submission time Handle Problem Language Result Execution time Memory
499806 2021-12-29T13:52:42 Z blue Safety (NOI18_safety) C++17
100 / 100
238 ms 20952 KB
#include <iostream>
#include <set>
#include <vector>
using namespace std;

using ll = long long;

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

    int N;
    ll H;
    cin >> N >> H;

    ll s0;
    cin >> s0;

    multiset<ll> left;
    ll left_lp = 0;

    multiset<ll> right;
    ll right_lp = 0;

    left.insert(s0);
    right.insert(s0);

    ll ans = 0;


    for(int i = 2; i <= N; i++)
    {
        ll S;
        cin >> S;

        left_lp -= H;
        right_lp += H;

        if(S <= left_lp + *left.rbegin())
        {
            ans += left_lp + *left.rbegin() - S;

            right.insert(-right_lp + *left.rbegin() + left_lp);
            left.erase(left.find(*left.rbegin()));
            left.insert(S - left_lp);
            left.insert(S - left_lp);
        }
        else if(S >= right_lp + *right.begin())
        {
            ans += S - (right_lp + *right.begin());

            left.insert(-left_lp + *right.begin() + right_lp);
            right.erase(right.find(*right.begin()));
            right.insert(S - right_lp);
            right.insert(S - right_lp);
        }
        else
        {
            left.insert(-left_lp + S);
            right.insert(-right_lp + S);
        }
    }

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 13884 KB Output is correct
2 Correct 196 ms 19636 KB Output is correct
3 Correct 238 ms 20500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
29 Correct 2 ms 584 KB Output is correct
30 Correct 2 ms 716 KB Output is correct
31 Correct 3 ms 588 KB Output is correct
32 Correct 2 ms 708 KB Output is correct
33 Correct 3 ms 656 KB Output is correct
34 Correct 2 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 716 KB Output is correct
35 Correct 2 ms 584 KB Output is correct
36 Correct 2 ms 716 KB Output is correct
37 Correct 3 ms 588 KB Output is correct
38 Correct 2 ms 708 KB Output is correct
39 Correct 3 ms 656 KB Output is correct
40 Correct 2 ms 752 KB Output is correct
41 Correct 3 ms 716 KB Output is correct
42 Correct 4 ms 712 KB Output is correct
43 Correct 2 ms 716 KB Output is correct
44 Correct 4 ms 716 KB Output is correct
45 Correct 2 ms 708 KB Output is correct
46 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 108 ms 13884 KB Output is correct
20 Correct 196 ms 19636 KB Output is correct
21 Correct 238 ms 20500 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 716 KB Output is correct
38 Correct 2 ms 584 KB Output is correct
39 Correct 2 ms 716 KB Output is correct
40 Correct 3 ms 588 KB Output is correct
41 Correct 2 ms 708 KB Output is correct
42 Correct 3 ms 656 KB Output is correct
43 Correct 2 ms 752 KB Output is correct
44 Correct 3 ms 716 KB Output is correct
45 Correct 4 ms 712 KB Output is correct
46 Correct 2 ms 716 KB Output is correct
47 Correct 4 ms 716 KB Output is correct
48 Correct 2 ms 708 KB Output is correct
49 Correct 2 ms 716 KB Output is correct
50 Correct 217 ms 20952 KB Output is correct
51 Correct 185 ms 17356 KB Output is correct
52 Correct 95 ms 16740 KB Output is correct
53 Correct 119 ms 19520 KB Output is correct
54 Correct 104 ms 20024 KB Output is correct
55 Correct 105 ms 17020 KB Output is correct
56 Correct 107 ms 18756 KB Output is correct
57 Correct 90 ms 17108 KB Output is correct
58 Correct 124 ms 14492 KB Output is correct
59 Correct 128 ms 18984 KB Output is correct