# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
385786 | 2021-04-05T00:25:50 Z | LucaDantas | Safety (NOI18_safety) | C++17 | 262 ms | 21100 KB |
#include <cstdio> #include <set> long long difl, difr; // lazy std::multiset<long long> l, r; long long ans = 0; void sl(int i) { int passar = *r.begin() + difr; r.erase(r.begin()); ans += (passar - (*l.rbegin() + difl)) * (-i + (int)l.size()); l.insert(passar - difl); } void sr(int i) { int passar = *l.rbegin() + difl; l.erase(--l.end()); ans -= (passar - (*l.rbegin() + difl)) * (-i + (int)l.size()); r.insert(passar - difr); } long long abs(long long a) { return a < 0 ? -a : a; } int main() { int n, k; scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) { long long a; scanf("%lld", &a); if(l.size()) ans += abs(a - *l.rbegin() - difl); if(!l.size() || a <= *l.rbegin() + difl) l.insert(a - difl), l.insert(a - difl); else r.insert(a - difr), r.insert(a - difr); while((int)l.size() > i) sr(i); while((int)r.size() > i) sl(i); difr += k; difl -= k; } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 256 KB | Output is correct |
6 | Correct | 1 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 150 ms | 12652 KB | Output is correct |
2 | Correct | 238 ms | 17900 KB | Output is correct |
3 | Correct | 259 ms | 18748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 256 KB | Output is correct |
11 | Correct | 1 ms | 256 KB | Output is correct |
12 | Correct | 1 ms | 256 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 256 KB | Output is correct |
11 | Correct | 1 ms | 256 KB | Output is correct |
12 | Correct | 1 ms | 256 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 256 KB | Output is correct |
11 | Correct | 1 ms | 256 KB | Output is correct |
12 | Correct | 1 ms | 256 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 5 ms | 748 KB | Output is correct |
29 | Correct | 4 ms | 748 KB | Output is correct |
30 | Correct | 4 ms | 748 KB | Output is correct |
31 | Correct | 3 ms | 748 KB | Output is correct |
32 | Correct | 3 ms | 748 KB | Output is correct |
33 | Correct | 4 ms | 748 KB | Output is correct |
34 | Correct | 4 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 256 KB | Output is correct |
11 | Correct | 1 ms | 256 KB | Output is correct |
12 | Correct | 1 ms | 256 KB | Output is correct |
13 | Correct | 1 ms | 256 KB | Output is correct |
14 | Correct | 1 ms | 256 KB | Output is correct |
15 | Correct | 1 ms | 256 KB | Output is correct |
16 | Correct | 1 ms | 256 KB | Output is correct |
17 | Correct | 1 ms | 256 KB | Output is correct |
18 | Correct | 1 ms | 256 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 1 ms | 364 KB | Output is correct |
31 | Correct | 1 ms | 364 KB | Output is correct |
32 | Correct | 1 ms | 364 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 5 ms | 748 KB | Output is correct |
35 | Correct | 4 ms | 748 KB | Output is correct |
36 | Correct | 4 ms | 748 KB | Output is correct |
37 | Correct | 3 ms | 748 KB | Output is correct |
38 | Correct | 3 ms | 748 KB | Output is correct |
39 | Correct | 4 ms | 748 KB | Output is correct |
40 | Correct | 4 ms | 748 KB | Output is correct |
41 | Correct | 4 ms | 876 KB | Output is correct |
42 | Correct | 3 ms | 748 KB | Output is correct |
43 | Correct | 4 ms | 748 KB | Output is correct |
44 | Correct | 4 ms | 748 KB | Output is correct |
45 | Correct | 4 ms | 748 KB | Output is correct |
46 | Correct | 4 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 256 KB | Output is correct |
11 | Correct | 1 ms | 256 KB | Output is correct |
12 | Correct | 1 ms | 256 KB | Output is correct |
13 | Correct | 1 ms | 256 KB | Output is correct |
14 | Correct | 1 ms | 256 KB | Output is correct |
15 | Correct | 1 ms | 256 KB | Output is correct |
16 | Correct | 1 ms | 256 KB | Output is correct |
17 | Correct | 1 ms | 256 KB | Output is correct |
18 | Correct | 1 ms | 256 KB | Output is correct |
19 | Correct | 150 ms | 12652 KB | Output is correct |
20 | Correct | 238 ms | 17900 KB | Output is correct |
21 | Correct | 259 ms | 18748 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 1 ms | 364 KB | Output is correct |
31 | Correct | 1 ms | 364 KB | Output is correct |
32 | Correct | 1 ms | 364 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 1 ms | 364 KB | Output is correct |
35 | Correct | 1 ms | 364 KB | Output is correct |
36 | Correct | 1 ms | 364 KB | Output is correct |
37 | Correct | 5 ms | 748 KB | Output is correct |
38 | Correct | 4 ms | 748 KB | Output is correct |
39 | Correct | 4 ms | 748 KB | Output is correct |
40 | Correct | 3 ms | 748 KB | Output is correct |
41 | Correct | 3 ms | 748 KB | Output is correct |
42 | Correct | 4 ms | 748 KB | Output is correct |
43 | Correct | 4 ms | 748 KB | Output is correct |
44 | Correct | 4 ms | 876 KB | Output is correct |
45 | Correct | 3 ms | 748 KB | Output is correct |
46 | Correct | 4 ms | 748 KB | Output is correct |
47 | Correct | 4 ms | 748 KB | Output is correct |
48 | Correct | 4 ms | 748 KB | Output is correct |
49 | Correct | 4 ms | 768 KB | Output is correct |
50 | Correct | 262 ms | 21100 KB | Output is correct |
51 | Correct | 204 ms | 17388 KB | Output is correct |
52 | Correct | 128 ms | 16748 KB | Output is correct |
53 | Correct | 150 ms | 19528 KB | Output is correct |
54 | Correct | 124 ms | 20076 KB | Output is correct |
55 | Correct | 130 ms | 17132 KB | Output is correct |
56 | Correct | 146 ms | 18924 KB | Output is correct |
57 | Correct | 131 ms | 17260 KB | Output is correct |
58 | Correct | 109 ms | 14444 KB | Output is correct |
59 | Correct | 138 ms | 19308 KB | Output is correct |