#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef tuple<int,int,int> T;
typedef pair<int,int> P;
int A[150005][3];
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
int i, j;
for(i=0;i<N;i++) {
for(j=0;j<3;j++) cin >> A[i][j];
}
priority_queue<P> Q[3];
for(i=0;i<N;i++) {
for(j=0;j<3;j++) Q[j].push(P(A[i][j],i));
}
int x[3];
for(i=0;i<3;i++) {
x[i] = Q[i].top().second;
Q[i].pop();
}
while(!Q[0].empty()||!Q[1].empty()||!Q[2].empty()) {
bool isChange = false;
for(i=0;i<3;i++) {
bool isWrong = false;
for(j=0;j<3;j++) {
if(i==j) continue;
if(A[x[i]][j]>=A[x[j]][j]) isWrong = true;
}
if(isWrong) {
if(!Q[i].empty()) {
x[i] = Q[i].top().second;
Q[i].pop();
break;
}
isChange = true;
}
}
//cout <<x[0] << ' ' << x[1] << ' ' << x[2] << '\n';
bool isCan = true;
for(i=0;i<3;i++) {
for(j=0;j<3;j++) {
if(i==j) continue;
if(A[x[i]][j]>=A[x[j]][j]) isCan = false;
}
}
if(isCan) {
int ans = 0;
for(i=0;i<3;i++) ans += A[x[i]][i];
cout << ans;
return 0;
}
}
cout << -1;
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:27:14: warning: variable 'isChange' set but not used [-Wunused-but-set-variable]
27 | bool isChange = false;
| ^~~~~~~~
# |
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 |
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 |
1 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 |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
356 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 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 |
0 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 |
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 |
1 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 |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
356 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 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 |
0 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 |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
680 KB |
Output is correct |
33 |
Correct |
2 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 |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
676 KB |
Output is correct |
39 |
Correct |
1 ms |
468 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 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 |
41 ms |
12132 KB |
Output is correct |
12 |
Correct |
44 ms |
7472 KB |
Output is correct |
13 |
Correct |
33 ms |
9140 KB |
Output is correct |
14 |
Correct |
91 ms |
12168 KB |
Output is correct |
15 |
Correct |
97 ms |
12188 KB |
Output is correct |
16 |
Correct |
79 ms |
12200 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 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 |
41 ms |
12132 KB |
Output is correct |
12 |
Correct |
44 ms |
7472 KB |
Output is correct |
13 |
Correct |
33 ms |
9140 KB |
Output is correct |
14 |
Correct |
91 ms |
12168 KB |
Output is correct |
15 |
Correct |
97 ms |
12188 KB |
Output is correct |
16 |
Correct |
79 ms |
12200 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
44 ms |
12108 KB |
Output is correct |
23 |
Correct |
52 ms |
12080 KB |
Output is correct |
24 |
Correct |
60 ms |
8104 KB |
Output is correct |
25 |
Correct |
126 ms |
12156 KB |
Output is correct |
26 |
Correct |
98 ms |
12124 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 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 |
41 ms |
12132 KB |
Output is correct |
12 |
Correct |
44 ms |
7472 KB |
Output is correct |
13 |
Correct |
33 ms |
9140 KB |
Output is correct |
14 |
Correct |
91 ms |
12168 KB |
Output is correct |
15 |
Correct |
97 ms |
12188 KB |
Output is correct |
16 |
Correct |
79 ms |
12200 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
44 ms |
12108 KB |
Output is correct |
23 |
Correct |
52 ms |
12080 KB |
Output is correct |
24 |
Correct |
60 ms |
8104 KB |
Output is correct |
25 |
Correct |
126 ms |
12156 KB |
Output is correct |
26 |
Correct |
98 ms |
12124 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
42 ms |
11944 KB |
Output is correct |
35 |
Correct |
66 ms |
11832 KB |
Output is correct |
36 |
Correct |
81 ms |
12196 KB |
Output is correct |
37 |
Correct |
132 ms |
12168 KB |
Output is correct |
38 |
Correct |
91 ms |
12140 KB |
Output is correct |
39 |
Correct |
53 ms |
6740 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 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 |
41 ms |
12132 KB |
Output is correct |
12 |
Correct |
44 ms |
7472 KB |
Output is correct |
13 |
Correct |
33 ms |
9140 KB |
Output is correct |
14 |
Correct |
91 ms |
12168 KB |
Output is correct |
15 |
Correct |
97 ms |
12188 KB |
Output is correct |
16 |
Correct |
79 ms |
12200 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
44 ms |
12108 KB |
Output is correct |
23 |
Correct |
52 ms |
12080 KB |
Output is correct |
24 |
Correct |
60 ms |
8104 KB |
Output is correct |
25 |
Correct |
126 ms |
12156 KB |
Output is correct |
26 |
Correct |
98 ms |
12124 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
42 ms |
11944 KB |
Output is correct |
35 |
Correct |
66 ms |
11832 KB |
Output is correct |
36 |
Correct |
81 ms |
12196 KB |
Output is correct |
37 |
Correct |
132 ms |
12168 KB |
Output is correct |
38 |
Correct |
91 ms |
12140 KB |
Output is correct |
39 |
Correct |
53 ms |
6740 KB |
Output is correct |
40 |
Correct |
2 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
2 ms |
596 KB |
Output is correct |
43 |
Correct |
3 ms |
596 KB |
Output is correct |
44 |
Correct |
60 ms |
12104 KB |
Output is correct |
45 |
Correct |
112 ms |
12200 KB |
Output is correct |
46 |
Correct |
97 ms |
12108 KB |
Output is correct |
47 |
Correct |
136 ms |
12148 KB |
Output is correct |
48 |
Correct |
114 ms |
12200 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 |
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 |
1 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 |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
356 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 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 |
0 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 |
596 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
3 ms |
680 KB |
Output is correct |
33 |
Correct |
2 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 |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
676 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
41 ms |
12132 KB |
Output is correct |
51 |
Correct |
44 ms |
7472 KB |
Output is correct |
52 |
Correct |
33 ms |
9140 KB |
Output is correct |
53 |
Correct |
91 ms |
12168 KB |
Output is correct |
54 |
Correct |
97 ms |
12188 KB |
Output is correct |
55 |
Correct |
79 ms |
12200 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
44 ms |
12108 KB |
Output is correct |
62 |
Correct |
52 ms |
12080 KB |
Output is correct |
63 |
Correct |
60 ms |
8104 KB |
Output is correct |
64 |
Correct |
126 ms |
12156 KB |
Output is correct |
65 |
Correct |
98 ms |
12124 KB |
Output is correct |
66 |
Correct |
0 ms |
340 KB |
Output is correct |
67 |
Correct |
0 ms |
340 KB |
Output is correct |
68 |
Correct |
0 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
3 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
2 ms |
340 KB |
Output is correct |
73 |
Correct |
42 ms |
11944 KB |
Output is correct |
74 |
Correct |
66 ms |
11832 KB |
Output is correct |
75 |
Correct |
81 ms |
12196 KB |
Output is correct |
76 |
Correct |
132 ms |
12168 KB |
Output is correct |
77 |
Correct |
91 ms |
12140 KB |
Output is correct |
78 |
Correct |
53 ms |
6740 KB |
Output is correct |
79 |
Correct |
2 ms |
596 KB |
Output is correct |
80 |
Correct |
2 ms |
596 KB |
Output is correct |
81 |
Correct |
2 ms |
596 KB |
Output is correct |
82 |
Correct |
3 ms |
596 KB |
Output is correct |
83 |
Correct |
60 ms |
12104 KB |
Output is correct |
84 |
Correct |
112 ms |
12200 KB |
Output is correct |
85 |
Correct |
97 ms |
12108 KB |
Output is correct |
86 |
Correct |
136 ms |
12148 KB |
Output is correct |
87 |
Correct |
114 ms |
12200 KB |
Output is correct |
88 |
Correct |
56 ms |
12144 KB |
Output is correct |
89 |
Correct |
103 ms |
12296 KB |
Output is correct |
90 |
Correct |
61 ms |
12160 KB |
Output is correct |
91 |
Correct |
158 ms |
12196 KB |
Output is correct |
92 |
Correct |
80 ms |
12308 KB |
Output is correct |
93 |
Correct |
108 ms |
12184 KB |
Output is correct |
94 |
Correct |
140 ms |
12176 KB |
Output is correct |
95 |
Correct |
110 ms |
12256 KB |
Output is correct |
96 |
Correct |
172 ms |
12212 KB |
Output is correct |
97 |
Correct |
95 ms |
12116 KB |
Output is correct |
98 |
Correct |
56 ms |
12196 KB |
Output is correct |
99 |
Correct |
105 ms |
12100 KB |
Output is correct |