#include <bits/stdc++.h>
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define WTF cout << "WTF" << endl
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int N = 2e5 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
int n;
int ns[N][3];
bool exist[N];
priority_queue<PII> ks[3];
int main() {
IOS;
cin >> n;
F0R(i, n) {
F0R(j, 3) {
cin >> ns[i][j];
ks[j].push({ns[i][j], i});
}
exist[i] = 1;
}
while(!ks[0].empty() && !ks[1].empty() && !ks[2].empty()) {
bool possible = 1;
F0R(i, 3) {
int id = ks[i].top().S;
F0R(j, 3) if (j != i && ns[id][j] >= ks[j].top().F) {
possible = 0;
exist[id] = 0;
}
}
if (possible) {
cout << ks[0].top().F + ks[1].top().F + ks[2].top().F;
return 0;
}
F0R(i, 3)
while(!ks[i].empty() && !exist[ks[i].top().S]) ks[i].pop();
}
cout << -1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
3 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
560 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
596 KB |
Output is correct |
34 |
Correct |
3 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
47 ms |
7092 KB |
Output is correct |
12 |
Correct |
55 ms |
4660 KB |
Output is correct |
13 |
Correct |
44 ms |
5632 KB |
Output is correct |
14 |
Correct |
94 ms |
7128 KB |
Output is correct |
15 |
Correct |
80 ms |
7036 KB |
Output is correct |
16 |
Correct |
67 ms |
7120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
47 ms |
7092 KB |
Output is correct |
12 |
Correct |
55 ms |
4660 KB |
Output is correct |
13 |
Correct |
44 ms |
5632 KB |
Output is correct |
14 |
Correct |
94 ms |
7128 KB |
Output is correct |
15 |
Correct |
80 ms |
7036 KB |
Output is correct |
16 |
Correct |
67 ms |
7120 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 |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
40 ms |
7360 KB |
Output is correct |
23 |
Correct |
58 ms |
7128 KB |
Output is correct |
24 |
Correct |
59 ms |
5112 KB |
Output is correct |
25 |
Correct |
102 ms |
7340 KB |
Output is correct |
26 |
Correct |
92 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
47 ms |
7092 KB |
Output is correct |
12 |
Correct |
55 ms |
4660 KB |
Output is correct |
13 |
Correct |
44 ms |
5632 KB |
Output is correct |
14 |
Correct |
94 ms |
7128 KB |
Output is correct |
15 |
Correct |
80 ms |
7036 KB |
Output is correct |
16 |
Correct |
67 ms |
7120 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 |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
40 ms |
7360 KB |
Output is correct |
23 |
Correct |
58 ms |
7128 KB |
Output is correct |
24 |
Correct |
59 ms |
5112 KB |
Output is correct |
25 |
Correct |
102 ms |
7340 KB |
Output is correct |
26 |
Correct |
92 ms |
7248 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
43 ms |
7760 KB |
Output is correct |
35 |
Correct |
59 ms |
7588 KB |
Output is correct |
36 |
Correct |
62 ms |
7752 KB |
Output is correct |
37 |
Correct |
103 ms |
7872 KB |
Output is correct |
38 |
Correct |
97 ms |
7664 KB |
Output is correct |
39 |
Correct |
60 ms |
4620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
47 ms |
7092 KB |
Output is correct |
12 |
Correct |
55 ms |
4660 KB |
Output is correct |
13 |
Correct |
44 ms |
5632 KB |
Output is correct |
14 |
Correct |
94 ms |
7128 KB |
Output is correct |
15 |
Correct |
80 ms |
7036 KB |
Output is correct |
16 |
Correct |
67 ms |
7120 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 |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
40 ms |
7360 KB |
Output is correct |
23 |
Correct |
58 ms |
7128 KB |
Output is correct |
24 |
Correct |
59 ms |
5112 KB |
Output is correct |
25 |
Correct |
102 ms |
7340 KB |
Output is correct |
26 |
Correct |
92 ms |
7248 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
43 ms |
7760 KB |
Output is correct |
35 |
Correct |
59 ms |
7588 KB |
Output is correct |
36 |
Correct |
62 ms |
7752 KB |
Output is correct |
37 |
Correct |
103 ms |
7872 KB |
Output is correct |
38 |
Correct |
97 ms |
7664 KB |
Output is correct |
39 |
Correct |
60 ms |
4620 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
48 ms |
8372 KB |
Output is correct |
45 |
Correct |
99 ms |
8244 KB |
Output is correct |
46 |
Correct |
93 ms |
8184 KB |
Output is correct |
47 |
Correct |
132 ms |
8236 KB |
Output is correct |
48 |
Correct |
87 ms |
8064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
3 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
560 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
596 KB |
Output is correct |
34 |
Correct |
3 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
468 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
320 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
324 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
47 ms |
7092 KB |
Output is correct |
51 |
Correct |
55 ms |
4660 KB |
Output is correct |
52 |
Correct |
44 ms |
5632 KB |
Output is correct |
53 |
Correct |
94 ms |
7128 KB |
Output is correct |
54 |
Correct |
80 ms |
7036 KB |
Output is correct |
55 |
Correct |
67 ms |
7120 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
40 ms |
7360 KB |
Output is correct |
62 |
Correct |
58 ms |
7128 KB |
Output is correct |
63 |
Correct |
59 ms |
5112 KB |
Output is correct |
64 |
Correct |
102 ms |
7340 KB |
Output is correct |
65 |
Correct |
92 ms |
7248 KB |
Output is correct |
66 |
Correct |
0 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
4 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
43 ms |
7760 KB |
Output is correct |
74 |
Correct |
59 ms |
7588 KB |
Output is correct |
75 |
Correct |
62 ms |
7752 KB |
Output is correct |
76 |
Correct |
103 ms |
7872 KB |
Output is correct |
77 |
Correct |
97 ms |
7664 KB |
Output is correct |
78 |
Correct |
60 ms |
4620 KB |
Output is correct |
79 |
Correct |
2 ms |
468 KB |
Output is correct |
80 |
Correct |
2 ms |
468 KB |
Output is correct |
81 |
Correct |
2 ms |
468 KB |
Output is correct |
82 |
Correct |
2 ms |
468 KB |
Output is correct |
83 |
Correct |
48 ms |
8372 KB |
Output is correct |
84 |
Correct |
99 ms |
8244 KB |
Output is correct |
85 |
Correct |
93 ms |
8184 KB |
Output is correct |
86 |
Correct |
132 ms |
8236 KB |
Output is correct |
87 |
Correct |
87 ms |
8064 KB |
Output is correct |
88 |
Correct |
60 ms |
9796 KB |
Output is correct |
89 |
Correct |
99 ms |
9820 KB |
Output is correct |
90 |
Correct |
83 ms |
9824 KB |
Output is correct |
91 |
Correct |
124 ms |
9780 KB |
Output is correct |
92 |
Correct |
62 ms |
8484 KB |
Output is correct |
93 |
Correct |
99 ms |
8824 KB |
Output is correct |
94 |
Correct |
120 ms |
8652 KB |
Output is correct |
95 |
Correct |
102 ms |
9644 KB |
Output is correct |
96 |
Correct |
105 ms |
9808 KB |
Output is correct |
97 |
Correct |
83 ms |
9864 KB |
Output is correct |
98 |
Correct |
54 ms |
8652 KB |
Output is correct |
99 |
Correct |
79 ms |
8612 KB |
Output is correct |