Submission #698038

# Submission time Handle Problem Language Result Execution time Memory
698038 2023-02-12T05:27:52 Z hotboy2703 Safety (NOI18_safety) C++17
100 / 100
208 ms 22540 KB
#include<bits/stdc++.h>
using namespace std;
long long n,h;
long long s[200100];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
    cin>>n>>h;
    for (long long i = 1;i <= n;i ++){
        cin>>s[i];
    }
    multiset <long long> l,r;
    long long add_l = 0,add_r = 0;
    long long a = 0, b = 0;
    for (long long i = 1;i <= n;i ++){
        add_l -= h;
        add_r += h;
        b += h * a;
        a--;
        b += s[i];
        l.insert(s[i] - add_l);
        l.insert(s[i] - add_l);
        while (!r.empty() && *l.rbegin() + add_l > *r.begin() + add_r){
            long long tmp = *l.rbegin() + add_l;
            l.erase(l.find(*l.rbegin()));
            r.insert(tmp - add_r);
        }
        while (l.size() > r.size()){
            long long tmp = *l.rbegin() + add_l;
           l.erase(l.find(*l.rbegin()));
            r.insert(tmp - add_r);
        }
        while (r.size() > l.size()){
            long long tmp = *r.begin() + add_r;
            r.erase(r.find(*r.begin()));
            l.insert(tmp - add_l);
        }
    }
    for (auto x:l){
        x += add_l;
        a++;
        b -= x;
        if (a == 0){
            cout<<b<<'\n';
            return 0;
        }
    }
    for (auto x:r){
        x += add_r;
        a++;
        b -= x;
        if (a == 0){
            cout<<b<<'\n';
            return 0;
        }
    }
    return 0;
}
# 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 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 14820 KB Output is correct
2 Correct 190 ms 21060 KB Output is correct
3 Correct 198 ms 22052 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 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 260 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 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 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 260 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 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 360 KB Output is correct
27 Correct 1 ms 340 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 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 260 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 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 360 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 4 ms 780 KB Output is correct
29 Correct 3 ms 728 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 3 ms 796 KB Output is correct
34 Correct 3 ms 752 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 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 260 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 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 360 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 4 ms 780 KB Output is correct
35 Correct 3 ms 728 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 2 ms 748 KB Output is correct
38 Correct 2 ms 724 KB Output is correct
39 Correct 3 ms 796 KB Output is correct
40 Correct 3 ms 752 KB Output is correct
41 Correct 3 ms 852 KB Output is correct
42 Correct 2 ms 728 KB Output is correct
43 Correct 3 ms 852 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 2 ms 732 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 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 260 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 124 ms 14820 KB Output is correct
20 Correct 190 ms 21060 KB Output is correct
21 Correct 198 ms 22052 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 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 360 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 4 ms 780 KB Output is correct
38 Correct 3 ms 728 KB Output is correct
39 Correct 3 ms 724 KB Output is correct
40 Correct 2 ms 748 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 3 ms 796 KB Output is correct
43 Correct 3 ms 752 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 2 ms 728 KB Output is correct
46 Correct 3 ms 852 KB Output is correct
47 Correct 3 ms 852 KB Output is correct
48 Correct 3 ms 724 KB Output is correct
49 Correct 2 ms 732 KB Output is correct
50 Correct 208 ms 22540 KB Output is correct
51 Correct 182 ms 18664 KB Output is correct
52 Correct 133 ms 17952 KB Output is correct
53 Correct 157 ms 20992 KB Output is correct
54 Correct 149 ms 21472 KB Output is correct
55 Correct 140 ms 18280 KB Output is correct
56 Correct 163 ms 20100 KB Output is correct
57 Correct 143 ms 18644 KB Output is correct
58 Correct 116 ms 15620 KB Output is correct
59 Correct 154 ms 20412 KB Output is correct