Submission #977861

# Submission time Handle Problem Language Result Execution time Memory
977861 2024-05-08T11:59:33 Z phoenix Safety (NOI18_safety) C++17
33 / 100
2000 ms 3080 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 200'200;

int n;

ll h;
ll s[N];


void solve() {
    cin >> n >> h;
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    
    multiset<ll> t1, t2;
    t1.insert(s[1]);
    t2.insert(s[1]);
    ll base = 0;

    for (int i = 2; i <= n; i++) {
        multiset<ll> st;
        {
            for (ll c : t1) st.insert(c - h);
            t1 = st;
            st.clear();
        }
        {
            for (ll c : t2) st.insert(c + h);
            t2 = st;
            st.clear();
        }
        ll l = *(--t1.end()), r = *t2.begin();
        if (l <= s[i] && s[i] <= r) {
            t1.insert(s[i]);
            t2.insert(s[i]);
        } else if (s[i] < l) {
            t1.insert(s[i]);
            t1.insert(s[i]);
            t1.erase(t1.find(l));
            t2.insert(l);
            base += l - s[i];
        } else {
            t2.insert(s[i]);
            t2.insert(s[i]);
            t2.erase(t2.find(r));
            t1.insert(r);
            base += s[i] - r;
        }
    }
    cout << base;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int test_cases = 1;
    // cin >> test_cases;
    while (test_cases-->0) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 500 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2051 ms 3080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 19 ms 348 KB Output is correct
14 Correct 20 ms 508 KB Output is correct
15 Correct 14 ms 528 KB Output is correct
16 Correct 14 ms 596 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
18 Correct 11 ms 496 KB Output is correct
19 Correct 16 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 19 ms 348 KB Output is correct
14 Correct 20 ms 508 KB Output is correct
15 Correct 14 ms 528 KB Output is correct
16 Correct 14 ms 596 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
18 Correct 11 ms 496 KB Output is correct
19 Correct 16 ms 348 KB Output is correct
20 Correct 12 ms 348 KB Output is correct
21 Correct 14 ms 348 KB Output is correct
22 Correct 10 ms 348 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 12 ms 528 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 19 ms 528 KB Output is correct
27 Correct 13 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 19 ms 348 KB Output is correct
14 Correct 20 ms 508 KB Output is correct
15 Correct 14 ms 528 KB Output is correct
16 Correct 14 ms 596 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
18 Correct 11 ms 496 KB Output is correct
19 Correct 16 ms 348 KB Output is correct
20 Correct 12 ms 348 KB Output is correct
21 Correct 14 ms 348 KB Output is correct
22 Correct 10 ms 348 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 12 ms 528 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 19 ms 528 KB Output is correct
27 Correct 13 ms 524 KB Output is correct
28 Execution timed out 2033 ms 1168 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Correct 19 ms 348 KB Output is correct
20 Correct 20 ms 508 KB Output is correct
21 Correct 14 ms 528 KB Output is correct
22 Correct 14 ms 596 KB Output is correct
23 Correct 11 ms 348 KB Output is correct
24 Correct 11 ms 496 KB Output is correct
25 Correct 16 ms 348 KB Output is correct
26 Correct 12 ms 348 KB Output is correct
27 Correct 14 ms 348 KB Output is correct
28 Correct 10 ms 348 KB Output is correct
29 Correct 8 ms 348 KB Output is correct
30 Correct 12 ms 528 KB Output is correct
31 Correct 9 ms 344 KB Output is correct
32 Correct 19 ms 528 KB Output is correct
33 Correct 13 ms 524 KB Output is correct
34 Execution timed out 2033 ms 1168 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 620 KB Output is correct
19 Execution timed out 2051 ms 3080 KB Time limit exceeded
20 Halted 0 ms 0 KB -