#include <cstdio>
#include <algorithm>
#include <utility>
#define f first
#define s second
using namespace std;
bool comp (pair <int, int> a, pair <int, int> b)
{
return a.f > b.f;
}
int main()
{
int n;
scanf("%d", &n);
pair <int, int> x[n], y[n], z[n];
int orix[n], oriy[n], oriz[n];
bool eliminated[n];
for (int i=0; i<n; i++)
{
scanf("%d %d %d", &orix[i], &oriy[i], &oriz[i]);
x[i].f=orix[i];
y[i].f=oriy[i];
z[i].f=oriz[i];
x[i].s=i;
y[i].s=i;
z[i].s=i;
eliminated[i]=false;
}
sort(x, x+n, comp);
sort(y, y+n, comp);
sort(z, z+n, comp);
int posx=0, posy=0, posz=0, ans=-1;
while (posx < n && posy < n && posz < n)
{
if (x[posx].s==y[posy].s && x[posx].s==z[posz].s)
{
eliminated[x[posx].s]=true;
posx++;
posy++;
posz++;
}
if (x[posx].s==y[posy].s)
{
eliminated[x[posx].s]=true;
posx++;
posy++;
}
else if (x[posx].s==z[posz].s)
{
eliminated[x[posx].s]=true;
posx++;
posz++;
}
else if (z[posz].s==y[posy].s)
{
eliminated[y[posy].s]=true;
}
else if (!eliminated[x[posx].s] && !eliminated[y[posy].s] && !eliminated[z[posz].s])
{
if (oriy[x[posx].s] >= y[posy].f || oriz[x[posx].s] >= z[posz].f)
posx++;
else if (orix[y[posy].s] >= x[posx].f || oriz[y[posy].s] >= z[posz].f)
posy++;
else if (oriy[z[posz].s] >= y[posy].f || orix[z[posz].s] >= x[posx].f)
posz++;
else
{
ans=x[posx].f + y[posy].f + z[posz].f;
break;
}
}
while (posx < n && eliminated[x[posx].s])
posx++;
while (posy < n && eliminated[y[posy].s])
posy++;
while (posz < n && eliminated[z[posz].s])
posz++;
}
printf("%d\n", ans);
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
team.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d %d %d", &orix[i], &oriy[i], &oriz[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 ms |
280 KB |
Output is correct |
10 |
Correct |
0 ms |
280 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
288 KB |
Output is correct |
16 |
Correct |
1 ms |
280 KB |
Output is correct |
17 |
Correct |
1 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
284 KB |
Output is correct |
21 |
Correct |
1 ms |
288 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 |
284 KB |
Output is correct |
25 |
Correct |
1 ms |
284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 ms |
280 KB |
Output is correct |
10 |
Correct |
0 ms |
280 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
288 KB |
Output is correct |
16 |
Correct |
1 ms |
280 KB |
Output is correct |
17 |
Correct |
1 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
284 KB |
Output is correct |
21 |
Correct |
1 ms |
288 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 |
284 KB |
Output is correct |
25 |
Correct |
1 ms |
284 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
420 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
524 KB |
Output is correct |
30 |
Correct |
2 ms |
408 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
516 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
524 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
2 ms |
420 KB |
Output is correct |
38 |
Correct |
2 ms |
472 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
53 ms |
6568 KB |
Output is correct |
12 |
Correct |
38 ms |
4396 KB |
Output is correct |
13 |
Correct |
42 ms |
5364 KB |
Output is correct |
14 |
Correct |
55 ms |
6564 KB |
Output is correct |
15 |
Correct |
55 ms |
6456 KB |
Output is correct |
16 |
Correct |
49 ms |
6560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
53 ms |
6568 KB |
Output is correct |
12 |
Correct |
38 ms |
4396 KB |
Output is correct |
13 |
Correct |
42 ms |
5364 KB |
Output is correct |
14 |
Correct |
55 ms |
6564 KB |
Output is correct |
15 |
Correct |
55 ms |
6456 KB |
Output is correct |
16 |
Correct |
49 ms |
6560 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 |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
66 ms |
6696 KB |
Output is correct |
23 |
Correct |
57 ms |
6476 KB |
Output is correct |
24 |
Correct |
45 ms |
4960 KB |
Output is correct |
25 |
Correct |
71 ms |
6812 KB |
Output is correct |
26 |
Correct |
56 ms |
6684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
53 ms |
6568 KB |
Output is correct |
12 |
Correct |
38 ms |
4396 KB |
Output is correct |
13 |
Correct |
42 ms |
5364 KB |
Output is correct |
14 |
Correct |
55 ms |
6564 KB |
Output is correct |
15 |
Correct |
55 ms |
6456 KB |
Output is correct |
16 |
Correct |
49 ms |
6560 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 |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
66 ms |
6696 KB |
Output is correct |
23 |
Correct |
57 ms |
6476 KB |
Output is correct |
24 |
Correct |
45 ms |
4960 KB |
Output is correct |
25 |
Correct |
71 ms |
6812 KB |
Output is correct |
26 |
Correct |
56 ms |
6684 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
66 ms |
6828 KB |
Output is correct |
35 |
Correct |
63 ms |
6476 KB |
Output is correct |
36 |
Correct |
69 ms |
7220 KB |
Output is correct |
37 |
Correct |
72 ms |
7244 KB |
Output is correct |
38 |
Correct |
58 ms |
7108 KB |
Output is correct |
39 |
Correct |
44 ms |
4504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
53 ms |
6568 KB |
Output is correct |
12 |
Correct |
38 ms |
4396 KB |
Output is correct |
13 |
Correct |
42 ms |
5364 KB |
Output is correct |
14 |
Correct |
55 ms |
6564 KB |
Output is correct |
15 |
Correct |
55 ms |
6456 KB |
Output is correct |
16 |
Correct |
49 ms |
6560 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 |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
66 ms |
6696 KB |
Output is correct |
23 |
Correct |
57 ms |
6476 KB |
Output is correct |
24 |
Correct |
45 ms |
4960 KB |
Output is correct |
25 |
Correct |
71 ms |
6812 KB |
Output is correct |
26 |
Correct |
56 ms |
6684 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
66 ms |
6828 KB |
Output is correct |
35 |
Correct |
63 ms |
6476 KB |
Output is correct |
36 |
Correct |
69 ms |
7220 KB |
Output is correct |
37 |
Correct |
72 ms |
7244 KB |
Output is correct |
38 |
Correct |
58 ms |
7108 KB |
Output is correct |
39 |
Correct |
44 ms |
4504 KB |
Output is correct |
40 |
Correct |
2 ms |
296 KB |
Output is correct |
41 |
Correct |
2 ms |
424 KB |
Output is correct |
42 |
Correct |
2 ms |
424 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
80 ms |
7736 KB |
Output is correct |
45 |
Correct |
80 ms |
7716 KB |
Output is correct |
46 |
Correct |
82 ms |
7724 KB |
Output is correct |
47 |
Correct |
99 ms |
7724 KB |
Output is correct |
48 |
Correct |
63 ms |
7700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 ms |
280 KB |
Output is correct |
10 |
Correct |
0 ms |
280 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
288 KB |
Output is correct |
16 |
Correct |
1 ms |
280 KB |
Output is correct |
17 |
Correct |
1 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
284 KB |
Output is correct |
21 |
Correct |
1 ms |
288 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 |
284 KB |
Output is correct |
25 |
Correct |
1 ms |
284 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
420 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
524 KB |
Output is correct |
30 |
Correct |
2 ms |
408 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
516 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
524 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
2 ms |
420 KB |
Output is correct |
38 |
Correct |
2 ms |
472 KB |
Output is correct |
39 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
53 ms |
6568 KB |
Output is correct |
51 |
Correct |
38 ms |
4396 KB |
Output is correct |
52 |
Correct |
42 ms |
5364 KB |
Output is correct |
53 |
Correct |
55 ms |
6564 KB |
Output is correct |
54 |
Correct |
55 ms |
6456 KB |
Output is correct |
55 |
Correct |
49 ms |
6560 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 |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
66 ms |
6696 KB |
Output is correct |
62 |
Correct |
57 ms |
6476 KB |
Output is correct |
63 |
Correct |
45 ms |
4960 KB |
Output is correct |
64 |
Correct |
71 ms |
6812 KB |
Output is correct |
65 |
Correct |
56 ms |
6684 KB |
Output is correct |
66 |
Correct |
0 ms |
212 KB |
Output is correct |
67 |
Correct |
1 ms |
212 KB |
Output is correct |
68 |
Correct |
0 ms |
212 KB |
Output is correct |
69 |
Correct |
1 ms |
212 KB |
Output is correct |
70 |
Correct |
2 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
66 ms |
6828 KB |
Output is correct |
74 |
Correct |
63 ms |
6476 KB |
Output is correct |
75 |
Correct |
69 ms |
7220 KB |
Output is correct |
76 |
Correct |
72 ms |
7244 KB |
Output is correct |
77 |
Correct |
58 ms |
7108 KB |
Output is correct |
78 |
Correct |
44 ms |
4504 KB |
Output is correct |
79 |
Correct |
2 ms |
296 KB |
Output is correct |
80 |
Correct |
2 ms |
424 KB |
Output is correct |
81 |
Correct |
2 ms |
424 KB |
Output is correct |
82 |
Correct |
2 ms |
468 KB |
Output is correct |
83 |
Correct |
80 ms |
7736 KB |
Output is correct |
84 |
Correct |
80 ms |
7716 KB |
Output is correct |
85 |
Correct |
82 ms |
7724 KB |
Output is correct |
86 |
Correct |
99 ms |
7724 KB |
Output is correct |
87 |
Correct |
63 ms |
7700 KB |
Output is correct |
88 |
Correct |
95 ms |
9592 KB |
Output is correct |
89 |
Correct |
97 ms |
9504 KB |
Output is correct |
90 |
Correct |
96 ms |
9516 KB |
Output is correct |
91 |
Correct |
100 ms |
9548 KB |
Output is correct |
92 |
Correct |
88 ms |
8108 KB |
Output is correct |
93 |
Correct |
95 ms |
8500 KB |
Output is correct |
94 |
Correct |
106 ms |
8304 KB |
Output is correct |
95 |
Correct |
77 ms |
9384 KB |
Output is correct |
96 |
Correct |
92 ms |
9512 KB |
Output is correct |
97 |
Correct |
65 ms |
9640 KB |
Output is correct |
98 |
Correct |
60 ms |
8236 KB |
Output is correct |
99 |
Correct |
79 ms |
8232 KB |
Output is correct |