# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
492704 | 2021-12-08T13:04:29 Z | zhougz | Discharging (NOI20_discharging) | C++17 | 138 ms | 13928 KB |
/** * author: chowgz * created: 14/03/2021 11:20:55 **/ #include <bits/stdc++.h> using namespace std; constexpr int MAXN = (int)1e6; struct Line { int m; long long c; long long operator()(int x) { return (long long)m * x + c; } double operator^(const Line &rhs) { return ((double)c - rhs.c) / ((double)rhs.m - m); } }; struct ConvexHull { Line lines[MAXN + 1]; int l = 0, r = 0; void operator+=(Line line) { while (r - l >= 2 && (line ^ lines[r - 1]) <= (lines[r - 1] ^ lines[r - 2])) { r--; } lines[r] = line; r++; } long long operator()(int x) { while (r - l >= 2 && lines[l](x) >= lines[l + 1](x)) { l++; } return lines[l](x); } } hull; // For more comments, check original cpp file! int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } long long dp; int maxx = 0; hull += Line{0, 0}; for (int i = 1; i <= n; i++) { if (arr[i - 1] > maxx) { maxx = arr[i - 1]; dp = n * (long long)maxx + hull(maxx); } hull += Line{-i, dp}; } cout << dp << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 316 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 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 | 0 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 | 0 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 328 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 0 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 328 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 0 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 0 ms | 332 KB | Output is correct |
16 | Correct | 105 ms | 9192 KB | Output is correct |
17 | Correct | 93 ms | 9956 KB | Output is correct |
18 | Correct | 71 ms | 8516 KB | Output is correct |
19 | Correct | 84 ms | 9960 KB | Output is correct |
20 | Correct | 82 ms | 9828 KB | Output is correct |
21 | Correct | 83 ms | 9972 KB | Output is correct |
22 | Correct | 87 ms | 9540 KB | Output is correct |
23 | Correct | 92 ms | 10624 KB | Output is correct |
24 | Correct | 84 ms | 10092 KB | Output is correct |
25 | Correct | 92 ms | 10476 KB | Output is correct |
26 | Correct | 92 ms | 10732 KB | Output is correct |
27 | Correct | 97 ms | 9196 KB | Output is correct |
28 | Correct | 103 ms | 10096 KB | Output is correct |
29 | Correct | 97 ms | 10232 KB | Output is correct |
30 | Correct | 98 ms | 10488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 109 ms | 13804 KB | Output is correct |
2 | Correct | 104 ms | 13892 KB | Output is correct |
3 | Correct | 102 ms | 13928 KB | Output is correct |
4 | Correct | 106 ms | 13924 KB | Output is correct |
5 | Correct | 138 ms | 13892 KB | Output is correct |
6 | Correct | 107 ms | 13800 KB | Output is correct |
7 | Correct | 97 ms | 13804 KB | Output is correct |
8 | Correct | 98 ms | 13808 KB | Output is correct |
9 | Correct | 107 ms | 13800 KB | Output is correct |
10 | Correct | 119 ms | 13800 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 316 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 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 | 0 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 | 0 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 328 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 | 328 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 0 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 | 0 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 | 204 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 0 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 204 KB | Output is correct |
31 | Correct | 1 ms | 324 KB | Output is correct |
32 | Correct | 0 ms | 204 KB | Output is correct |
33 | Correct | 1 ms | 204 KB | Output is correct |
34 | Correct | 1 ms | 204 KB | Output is correct |
35 | Correct | 1 ms | 332 KB | Output is correct |
36 | Correct | 1 ms | 332 KB | Output is correct |
37 | Correct | 0 ms | 204 KB | Output is correct |
38 | Correct | 1 ms | 204 KB | Output is correct |
39 | Correct | 1 ms | 204 KB | Output is correct |
40 | Correct | 1 ms | 332 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
42 | Correct | 1 ms | 332 KB | Output is correct |
43 | Correct | 1 ms | 204 KB | Output is correct |
44 | Correct | 1 ms | 204 KB | Output is correct |
45 | Correct | 1 ms | 204 KB | Output is correct |
46 | Correct | 1 ms | 384 KB | Output is correct |
47 | Correct | 0 ms | 204 KB | Output is correct |
48 | Correct | 1 ms | 332 KB | Output is correct |
49 | Correct | 1 ms | 332 KB | Output is correct |
50 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 316 KB | Output is correct |
3 | Correct | 0 ms | 204 KB | Output is correct |
4 | Correct | 0 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 | 0 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 | 0 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 0 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 328 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 | 328 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 0 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 | 0 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 | 204 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 0 ms | 332 KB | Output is correct |
30 | Correct | 105 ms | 9192 KB | Output is correct |
31 | Correct | 93 ms | 9956 KB | Output is correct |
32 | Correct | 71 ms | 8516 KB | Output is correct |
33 | Correct | 84 ms | 9960 KB | Output is correct |
34 | Correct | 82 ms | 9828 KB | Output is correct |
35 | Correct | 83 ms | 9972 KB | Output is correct |
36 | Correct | 87 ms | 9540 KB | Output is correct |
37 | Correct | 92 ms | 10624 KB | Output is correct |
38 | Correct | 84 ms | 10092 KB | Output is correct |
39 | Correct | 92 ms | 10476 KB | Output is correct |
40 | Correct | 92 ms | 10732 KB | Output is correct |
41 | Correct | 97 ms | 9196 KB | Output is correct |
42 | Correct | 103 ms | 10096 KB | Output is correct |
43 | Correct | 97 ms | 10232 KB | Output is correct |
44 | Correct | 98 ms | 10488 KB | Output is correct |
45 | Correct | 109 ms | 13804 KB | Output is correct |
46 | Correct | 104 ms | 13892 KB | Output is correct |
47 | Correct | 102 ms | 13928 KB | Output is correct |
48 | Correct | 106 ms | 13924 KB | Output is correct |
49 | Correct | 138 ms | 13892 KB | Output is correct |
50 | Correct | 107 ms | 13800 KB | Output is correct |
51 | Correct | 97 ms | 13804 KB | Output is correct |
52 | Correct | 98 ms | 13808 KB | Output is correct |
53 | Correct | 107 ms | 13800 KB | Output is correct |
54 | Correct | 119 ms | 13800 KB | Output is correct |
55 | Correct | 1 ms | 204 KB | Output is correct |
56 | Correct | 1 ms | 324 KB | Output is correct |
57 | Correct | 0 ms | 204 KB | Output is correct |
58 | Correct | 1 ms | 204 KB | Output is correct |
59 | Correct | 1 ms | 204 KB | Output is correct |
60 | Correct | 1 ms | 332 KB | Output is correct |
61 | Correct | 1 ms | 332 KB | Output is correct |
62 | Correct | 0 ms | 204 KB | Output is correct |
63 | Correct | 1 ms | 204 KB | Output is correct |
64 | Correct | 1 ms | 204 KB | Output is correct |
65 | Correct | 1 ms | 332 KB | Output is correct |
66 | Correct | 1 ms | 332 KB | Output is correct |
67 | Correct | 1 ms | 332 KB | Output is correct |
68 | Correct | 1 ms | 204 KB | Output is correct |
69 | Correct | 1 ms | 204 KB | Output is correct |
70 | Correct | 1 ms | 204 KB | Output is correct |
71 | Correct | 1 ms | 384 KB | Output is correct |
72 | Correct | 0 ms | 204 KB | Output is correct |
73 | Correct | 1 ms | 332 KB | Output is correct |
74 | Correct | 1 ms | 332 KB | Output is correct |
75 | Correct | 1 ms | 332 KB | Output is correct |
76 | Correct | 84 ms | 10224 KB | Output is correct |
77 | Correct | 87 ms | 10160 KB | Output is correct |
78 | Correct | 89 ms | 9800 KB | Output is correct |
79 | Correct | 85 ms | 9960 KB | Output is correct |
80 | Correct | 86 ms | 10484 KB | Output is correct |
81 | Correct | 79 ms | 9704 KB | Output is correct |
82 | Correct | 77 ms | 9704 KB | Output is correct |
83 | Correct | 83 ms | 10084 KB | Output is correct |
84 | Correct | 100 ms | 9924 KB | Output is correct |
85 | Correct | 87 ms | 10180 KB | Output is correct |
86 | Correct | 83 ms | 9576 KB | Output is correct |
87 | Correct | 79 ms | 9464 KB | Output is correct |
88 | Correct | 82 ms | 9940 KB | Output is correct |
89 | Correct | 98 ms | 9704 KB | Output is correct |
90 | Correct | 96 ms | 9584 KB | Output is correct |
91 | Correct | 78 ms | 9412 KB | Output is correct |
92 | Correct | 88 ms | 10728 KB | Output is correct |
93 | Correct | 88 ms | 9956 KB | Output is correct |
94 | Correct | 98 ms | 9068 KB | Output is correct |
95 | Correct | 99 ms | 10476 KB | Output is correct |
96 | Correct | 78 ms | 9464 KB | Output is correct |
97 | Correct | 80 ms | 9716 KB | Output is correct |
98 | Correct | 81 ms | 9960 KB | Output is correct |
99 | Correct | 88 ms | 9672 KB | Output is correct |
100 | Correct | 90 ms | 9832 KB | Output is correct |