Submission #412991

# Submission time Handle Problem Language Result Execution time Memory
412991 2021-05-28T00:20:05 Z Bench0310 Safety (NOI18_safety) C++17
100 / 100
164 ms 16796 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 i128;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll h;
    cin >> n >> h;
    i128 m=0,b=0;
    priority_queue<i128> l;
    priority_queue<i128,vector<i128>,greater<i128>> r;
    i128 dl=0,dr=0; //real value is x+dx
    for(int i=0;i<n;i++)
    {
        ll s;
        cin >> s;
        //f->g
        dl-=h;
        dr+=h;
        b+=(m*h);
        //add c
        if(i==0||s<=l.top()+dl)
        {
            l.push(s-dl);
            l.push(s-dl);
            i128 t=l.top()+dl;
            l.pop();
            r.push(t-dr);
        }
        else
        {
            r.push(s-dr);
            r.push(s-dr);
            i128 t=r.top()+dr;
            r.pop();
            l.push(t-dl);
        }
        m--;
        b+=s;
    }
    vector<i128> v;
    for(int i=0;i<n;i++)
    {
        i128 t=l.top();
        l.pop();
        v.push_back(t+dl);
    }
    reverse(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        i128 t=r.top();
        r.pop();
        v.push_back(t+dr);
    }
    i128 res=(1ll<<60);
    for(i128 x:v)
    {
        i128 y=m*x+b;
        m++;
        b=y-m*x;
        res=min(res,y);
    }
    cout << ll(res) << "\n";
    return 0;
}
# 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 1 ms 204 KB Output is correct
7 Correct 1 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 312 KB Output is correct
5 Correct 1 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 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 14000 KB Output is correct
2 Correct 151 ms 16332 KB Output is correct
3 Correct 160 ms 16588 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 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 332 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 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 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 332 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 320 KB Output is correct
24 Correct 1 ms 316 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 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 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 332 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 320 KB Output is correct
24 Correct 1 ms 316 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 3 ms 844 KB Output is correct
29 Correct 3 ms 844 KB Output is correct
30 Correct 3 ms 844 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 3 ms 844 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 3 ms 844 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 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 1 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 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 1 ms 332 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 316 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 3 ms 844 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 3 ms 844 KB Output is correct
37 Correct 3 ms 716 KB Output is correct
38 Correct 3 ms 844 KB Output is correct
39 Correct 3 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 4 ms 972 KB Output is correct
42 Correct 3 ms 716 KB Output is correct
43 Correct 3 ms 972 KB Output is correct
44 Correct 4 ms 908 KB Output is correct
45 Correct 3 ms 844 KB Output is correct
46 Correct 3 ms 844 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 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 1 ms 204 KB Output is correct
19 Correct 101 ms 14000 KB Output is correct
20 Correct 151 ms 16332 KB Output is correct
21 Correct 160 ms 16588 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 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 320 KB Output is correct
33 Correct 1 ms 316 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 3 ms 844 KB Output is correct
38 Correct 3 ms 844 KB Output is correct
39 Correct 3 ms 844 KB Output is correct
40 Correct 3 ms 716 KB Output is correct
41 Correct 3 ms 844 KB Output is correct
42 Correct 3 ms 844 KB Output is correct
43 Correct 3 ms 844 KB Output is correct
44 Correct 4 ms 972 KB Output is correct
45 Correct 3 ms 716 KB Output is correct
46 Correct 3 ms 972 KB Output is correct
47 Correct 4 ms 908 KB Output is correct
48 Correct 3 ms 844 KB Output is correct
49 Correct 3 ms 844 KB Output is correct
50 Correct 164 ms 16796 KB Output is correct
51 Correct 130 ms 15436 KB Output is correct
52 Correct 104 ms 15204 KB Output is correct
53 Correct 123 ms 16252 KB Output is correct
54 Correct 126 ms 16400 KB Output is correct
55 Correct 104 ms 15288 KB Output is correct
56 Correct 117 ms 16056 KB Output is correct
57 Correct 106 ms 15372 KB Output is correct
58 Correct 93 ms 14004 KB Output is correct
59 Correct 119 ms 16012 KB Output is correct