Submission #102095

# Submission time Handle Problem Language Result Execution time Memory
102095 2019-03-22T09:11:43 Z win11905 Safety (NOI18_safety) C++11
100 / 100
357 ms 19212 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 2e5+5;

class safety {
private:
    int n;
    long k, high, now;
    multiset<long> Sl, Sr;
public:
    void solve(istream& cin, ostream& cout) {
        cin >> n >> k;
        for(int i = 0; i < n; ++i) {
            cin >> now;
            high += now;
            Sl.emplace(now + i*k), Sr.emplace(now - i*k);
            while(*Sl.rbegin() - i*k > *Sr.begin() + i*k) {
                long a = *Sl.rbegin(), b = *Sr.begin();
                Sl.erase(Sl.find(*Sl.rbegin())), Sr.erase(Sr.find(*Sr.begin()));
                Sl.emplace(b + 2*i*k), Sr.emplace(a - 2*i*k);
            }
            long pv = 0;
            while(!Sl.empty() && *Sl.begin() - i*k <= k) {
                high -= Sl.size() * (*Sl.begin() - i*k - pv);
                pv = *Sl.begin() - i*k;
                Sl.erase(Sl.begin());
            }
            high -= Sl.size() * (k - pv);
        }
        long pv = 0, ptr = Sl.size();
        for(auto x : Sl) {
            high -= ptr-- * (x - n*k - pv);
            pv = x - n*k;
        }
        cout << high << endl;
    }
};

class Solver {
public:
    void solve(std::istream& in, std::ostream& out) {
        safety *obj = new safety();
        obj->solve(in, out);
    }
};

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Solver solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 12792 KB Output is correct
2 Correct 357 ms 18172 KB Output is correct
3 Correct 342 ms 18676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 6 ms 632 KB Output is correct
29 Correct 5 ms 760 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 3 ms 456 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 380 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 6 ms 632 KB Output is correct
35 Correct 5 ms 760 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 3 ms 456 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 4 ms 504 KB Output is correct
40 Correct 4 ms 632 KB Output is correct
41 Correct 6 ms 760 KB Output is correct
42 Correct 5 ms 764 KB Output is correct
43 Correct 4 ms 632 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 200 ms 12792 KB Output is correct
20 Correct 357 ms 18172 KB Output is correct
21 Correct 342 ms 18676 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 6 ms 632 KB Output is correct
38 Correct 5 ms 760 KB Output is correct
39 Correct 4 ms 504 KB Output is correct
40 Correct 3 ms 456 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 4 ms 504 KB Output is correct
43 Correct 4 ms 632 KB Output is correct
44 Correct 6 ms 760 KB Output is correct
45 Correct 5 ms 764 KB Output is correct
46 Correct 4 ms 632 KB Output is correct
47 Correct 4 ms 504 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 4 ms 504 KB Output is correct
50 Correct 326 ms 19212 KB Output is correct
51 Correct 271 ms 15984 KB Output is correct
52 Correct 79 ms 7800 KB Output is correct
53 Correct 93 ms 9128 KB Output is correct
54 Correct 108 ms 9312 KB Output is correct
55 Correct 83 ms 8056 KB Output is correct
56 Correct 96 ms 8696 KB Output is correct
57 Correct 82 ms 8056 KB Output is correct
58 Correct 94 ms 6904 KB Output is correct
59 Correct 99 ms 8824 KB Output is correct