Submission #576187

# Submission time Handle Problem Language Result Execution time Memory
576187 2022-06-12T13:18:35 Z erekle Team Contest (JOI22_team) C++17
100 / 100
223 ms 9856 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> x(n), y(n), z(n);
    for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> z[i];
    
    vector<int> byX(n);
    for (int i = 0; i < n; ++i) byX[i] = i;
    sort(byX.begin(), byX.end(), [&x](int i, int j){return x[i]>x[j];});

    priority_queue<pair<int, int>> byY, byZ;
    for (int i = 0; i < n; ++i) {
        byY.emplace(y[i], i);
        byZ.emplace(z[i], i);
    }

    int bestTeam = -1;
    for (int i : byX) {
        while (!byY.empty() && !byZ.empty()) {
            if (x[byY.top().second] >= x[i]) byY.pop();
            else if (x[byZ.top().second] >= x[i]) byZ.pop();
            else if (z[byY.top().second] >= byZ.top().first) byY.pop();
            else if (y[byZ.top().second] >= byY.top().first) byZ.pop();
            /* For the two lines above, >= is necessary rather than simply ==
            This is because a beaver may have been deleted from byZ since it was both y-maximal and z-maximal
            but not from byY, since we do not find and delete these double maximal beavers from the other pq.
            This means the z value of a beaver in byY may be greater than the largest z value in byZ.
            The same applies to the y values of beavers in byZ.
            */
            else break;
        }
        if (!byY.empty() && !byZ.empty()) {
            int j = byY.top().second, k = byZ.top().second;
            assert(y[j] > y[k]); assert(z[k] > z[j]);
            int Y = byY.top().first, Z = byZ.top().first;
            if (Y > y[i] && Z > z[i]) bestTeam = max(bestTeam, x[i] + Y + Z);
        }
    }
    cout << bestTeam << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 6 ms 440 KB Output is correct
27 Correct 7 ms 468 KB Output is correct
28 Correct 6 ms 452 KB Output is correct
29 Correct 6 ms 440 KB Output is correct
30 Correct 3 ms 440 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 4 ms 396 KB Output is correct
33 Correct 5 ms 468 KB Output is correct
34 Correct 6 ms 452 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 4 ms 468 KB Output is correct
38 Correct 4 ms 468 KB Output is correct
39 Correct 2 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 1 ms 300 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 87 ms 6756 KB Output is correct
12 Correct 64 ms 4160 KB Output is correct
13 Correct 68 ms 5108 KB Output is correct
14 Correct 92 ms 6756 KB Output is correct
15 Correct 84 ms 6836 KB Output is correct
16 Correct 80 ms 6748 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 1 ms 300 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 87 ms 6756 KB Output is correct
12 Correct 64 ms 4160 KB Output is correct
13 Correct 68 ms 5108 KB Output is correct
14 Correct 92 ms 6756 KB Output is correct
15 Correct 84 ms 6836 KB Output is correct
16 Correct 80 ms 6748 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 101 ms 7072 KB Output is correct
23 Correct 97 ms 6868 KB Output is correct
24 Correct 80 ms 4616 KB Output is correct
25 Correct 114 ms 7024 KB Output is correct
26 Correct 106 ms 6884 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 1 ms 300 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 87 ms 6756 KB Output is correct
12 Correct 64 ms 4160 KB Output is correct
13 Correct 68 ms 5108 KB Output is correct
14 Correct 92 ms 6756 KB Output is correct
15 Correct 84 ms 6836 KB Output is correct
16 Correct 80 ms 6748 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 101 ms 7072 KB Output is correct
23 Correct 97 ms 6868 KB Output is correct
24 Correct 80 ms 4616 KB Output is correct
25 Correct 114 ms 7024 KB Output is correct
26 Correct 106 ms 6884 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 116 ms 7356 KB Output is correct
35 Correct 111 ms 7092 KB Output is correct
36 Correct 122 ms 7396 KB Output is correct
37 Correct 145 ms 7600 KB Output is correct
38 Correct 106 ms 7360 KB Output is correct
39 Correct 64 ms 4368 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 1 ms 300 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 87 ms 6756 KB Output is correct
12 Correct 64 ms 4160 KB Output is correct
13 Correct 68 ms 5108 KB Output is correct
14 Correct 92 ms 6756 KB Output is correct
15 Correct 84 ms 6836 KB Output is correct
16 Correct 80 ms 6748 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 101 ms 7072 KB Output is correct
23 Correct 97 ms 6868 KB Output is correct
24 Correct 80 ms 4616 KB Output is correct
25 Correct 114 ms 7024 KB Output is correct
26 Correct 106 ms 6884 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 116 ms 7356 KB Output is correct
35 Correct 111 ms 7092 KB Output is correct
36 Correct 122 ms 7396 KB Output is correct
37 Correct 145 ms 7600 KB Output is correct
38 Correct 106 ms 7360 KB Output is correct
39 Correct 64 ms 4368 KB Output is correct
40 Correct 4 ms 340 KB Output is correct
41 Correct 4 ms 388 KB Output is correct
42 Correct 4 ms 468 KB Output is correct
43 Correct 4 ms 468 KB Output is correct
44 Correct 151 ms 7916 KB Output is correct
45 Correct 157 ms 8120 KB Output is correct
46 Correct 152 ms 8000 KB Output is correct
47 Correct 158 ms 8048 KB Output is correct
48 Correct 135 ms 8008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 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 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 6 ms 440 KB Output is correct
27 Correct 7 ms 468 KB Output is correct
28 Correct 6 ms 452 KB Output is correct
29 Correct 6 ms 440 KB Output is correct
30 Correct 3 ms 440 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 4 ms 396 KB Output is correct
33 Correct 5 ms 468 KB Output is correct
34 Correct 6 ms 452 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 4 ms 468 KB Output is correct
38 Correct 4 ms 468 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 0 ms 300 KB Output is correct
44 Correct 1 ms 296 KB Output is correct
45 Correct 0 ms 304 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 87 ms 6756 KB Output is correct
51 Correct 64 ms 4160 KB Output is correct
52 Correct 68 ms 5108 KB Output is correct
53 Correct 92 ms 6756 KB Output is correct
54 Correct 84 ms 6836 KB Output is correct
55 Correct 80 ms 6748 KB Output is correct
56 Correct 0 ms 300 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 300 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 101 ms 7072 KB Output is correct
62 Correct 97 ms 6868 KB Output is correct
63 Correct 80 ms 4616 KB Output is correct
64 Correct 114 ms 7024 KB Output is correct
65 Correct 106 ms 6884 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 300 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 4 ms 468 KB Output is correct
71 Correct 1 ms 308 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 116 ms 7356 KB Output is correct
74 Correct 111 ms 7092 KB Output is correct
75 Correct 122 ms 7396 KB Output is correct
76 Correct 145 ms 7600 KB Output is correct
77 Correct 106 ms 7360 KB Output is correct
78 Correct 64 ms 4368 KB Output is correct
79 Correct 4 ms 340 KB Output is correct
80 Correct 4 ms 388 KB Output is correct
81 Correct 4 ms 468 KB Output is correct
82 Correct 4 ms 468 KB Output is correct
83 Correct 151 ms 7916 KB Output is correct
84 Correct 157 ms 8120 KB Output is correct
85 Correct 152 ms 8000 KB Output is correct
86 Correct 158 ms 8048 KB Output is correct
87 Correct 135 ms 8008 KB Output is correct
88 Correct 196 ms 9832 KB Output is correct
89 Correct 223 ms 9788 KB Output is correct
90 Correct 221 ms 9840 KB Output is correct
91 Correct 220 ms 9712 KB Output is correct
92 Correct 152 ms 8284 KB Output is correct
93 Correct 178 ms 8632 KB Output is correct
94 Correct 181 ms 8612 KB Output is correct
95 Correct 181 ms 9704 KB Output is correct
96 Correct 213 ms 9856 KB Output is correct
97 Correct 215 ms 9848 KB Output is correct
98 Correct 148 ms 8416 KB Output is correct
99 Correct 154 ms 8376 KB Output is correct