/* Im the best and i work like that */
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define Mp make_pair
#define point complex
#define endl '\n'
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file_io freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define mashtali return cout << "Hello, World!", 0;
const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
const double pi = acos(-1);
const ld eps = 1e-18;
const ld one = 1.;
ll pw(ll a, ll b, ll M, ll ret = 1) { if(a == 0) return 0; a %= M; while(b) { ret = (b & 1? ret * a % M : ret), a = a * a % M, b >>= 1; } return ret % M; }
mt19937 rng(time(nullptr));
int n, A[N], B[N], C[N];
int main()
{
fast_io;
set < pii > a, b, c;
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> A[i] >> B[i] >> C[i];
a.insert(Mp(-A[i], i));
b.insert(Mp(-B[i], i));
c.insert(Mp(-C[i], i));
}
while(SZ(a))
{
pii aa = *a.begin();
pii bb = *b.begin();
pii cc = *c.begin();
aa.F *= -1;
bb.F *= -1;
cc.F *= -1;
///cout << aa.F << " " << bb.F << " " << cc.F << endl;
int id = aa.S;
if(B[id] >= bb.F || C[aa.S] >= cc.F)
{
a.erase(Mp(-A[id], id));
b.erase(Mp(-B[id], id));
c.erase(Mp(-C[id], id));
continue;
}
id = bb.S;
if(A[id] >= aa.F || C[id] >= cc.F)
{
a.erase(Mp(-A[id], id));
b.erase(Mp(-B[id], id));
c.erase(Mp(-C[id], id));
continue;
}
id = cc.S;
if(A[id] >= aa.F || B[id] >= bb.F)
{
a.erase(Mp(-A[id], id));
b.erase(Mp(-B[id], id));
c.erase(Mp(-C[id], id));
continue;
}
cout << aa.F + bb.F + cc.F << endl;
return 0;
}
cout << -1 << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
328 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
328 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 |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
4 ms |
888 KB |
Output is correct |
28 |
Correct |
5 ms |
980 KB |
Output is correct |
29 |
Correct |
5 ms |
996 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
5 ms |
988 KB |
Output is correct |
33 |
Correct |
5 ms |
972 KB |
Output is correct |
34 |
Correct |
4 ms |
976 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
904 KB |
Output is correct |
38 |
Correct |
4 ms |
980 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
171 ms |
23732 KB |
Output is correct |
12 |
Correct |
129 ms |
15976 KB |
Output is correct |
13 |
Correct |
106 ms |
19872 KB |
Output is correct |
14 |
Correct |
197 ms |
23952 KB |
Output is correct |
15 |
Correct |
150 ms |
23604 KB |
Output is correct |
16 |
Correct |
146 ms |
23952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
171 ms |
23732 KB |
Output is correct |
12 |
Correct |
129 ms |
15976 KB |
Output is correct |
13 |
Correct |
106 ms |
19872 KB |
Output is correct |
14 |
Correct |
197 ms |
23952 KB |
Output is correct |
15 |
Correct |
150 ms |
23604 KB |
Output is correct |
16 |
Correct |
146 ms |
23952 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
188 ms |
24112 KB |
Output is correct |
23 |
Correct |
192 ms |
23420 KB |
Output is correct |
24 |
Correct |
174 ms |
17616 KB |
Output is correct |
25 |
Correct |
269 ms |
24136 KB |
Output is correct |
26 |
Correct |
166 ms |
24192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
171 ms |
23732 KB |
Output is correct |
12 |
Correct |
129 ms |
15976 KB |
Output is correct |
13 |
Correct |
106 ms |
19872 KB |
Output is correct |
14 |
Correct |
197 ms |
23952 KB |
Output is correct |
15 |
Correct |
150 ms |
23604 KB |
Output is correct |
16 |
Correct |
146 ms |
23952 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
188 ms |
24112 KB |
Output is correct |
23 |
Correct |
192 ms |
23420 KB |
Output is correct |
24 |
Correct |
174 ms |
17616 KB |
Output is correct |
25 |
Correct |
269 ms |
24136 KB |
Output is correct |
26 |
Correct |
166 ms |
24192 KB |
Output is correct |
27 |
Correct |
1 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 |
5 ms |
992 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
259 ms |
23448 KB |
Output is correct |
35 |
Correct |
288 ms |
21940 KB |
Output is correct |
36 |
Correct |
325 ms |
24300 KB |
Output is correct |
37 |
Correct |
400 ms |
24672 KB |
Output is correct |
38 |
Correct |
205 ms |
23768 KB |
Output is correct |
39 |
Correct |
96 ms |
14680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
171 ms |
23732 KB |
Output is correct |
12 |
Correct |
129 ms |
15976 KB |
Output is correct |
13 |
Correct |
106 ms |
19872 KB |
Output is correct |
14 |
Correct |
197 ms |
23952 KB |
Output is correct |
15 |
Correct |
150 ms |
23604 KB |
Output is correct |
16 |
Correct |
146 ms |
23952 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
188 ms |
24112 KB |
Output is correct |
23 |
Correct |
192 ms |
23420 KB |
Output is correct |
24 |
Correct |
174 ms |
17616 KB |
Output is correct |
25 |
Correct |
269 ms |
24136 KB |
Output is correct |
26 |
Correct |
166 ms |
24192 KB |
Output is correct |
27 |
Correct |
1 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 |
5 ms |
992 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
259 ms |
23448 KB |
Output is correct |
35 |
Correct |
288 ms |
21940 KB |
Output is correct |
36 |
Correct |
325 ms |
24300 KB |
Output is correct |
37 |
Correct |
400 ms |
24672 KB |
Output is correct |
38 |
Correct |
205 ms |
23768 KB |
Output is correct |
39 |
Correct |
96 ms |
14680 KB |
Output is correct |
40 |
Correct |
3 ms |
724 KB |
Output is correct |
41 |
Correct |
4 ms |
984 KB |
Output is correct |
42 |
Correct |
3 ms |
852 KB |
Output is correct |
43 |
Correct |
3 ms |
980 KB |
Output is correct |
44 |
Correct |
344 ms |
25180 KB |
Output is correct |
45 |
Correct |
446 ms |
25152 KB |
Output is correct |
46 |
Correct |
429 ms |
24596 KB |
Output is correct |
47 |
Correct |
459 ms |
25440 KB |
Output is correct |
48 |
Correct |
243 ms |
25164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
328 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 |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
4 ms |
888 KB |
Output is correct |
28 |
Correct |
5 ms |
980 KB |
Output is correct |
29 |
Correct |
5 ms |
996 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
5 ms |
988 KB |
Output is correct |
33 |
Correct |
5 ms |
972 KB |
Output is correct |
34 |
Correct |
4 ms |
976 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
904 KB |
Output is correct |
38 |
Correct |
4 ms |
980 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
328 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
0 ms |
340 KB |
Output is correct |
50 |
Correct |
171 ms |
23732 KB |
Output is correct |
51 |
Correct |
129 ms |
15976 KB |
Output is correct |
52 |
Correct |
106 ms |
19872 KB |
Output is correct |
53 |
Correct |
197 ms |
23952 KB |
Output is correct |
54 |
Correct |
150 ms |
23604 KB |
Output is correct |
55 |
Correct |
146 ms |
23952 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
596 KB |
Output is correct |
61 |
Correct |
188 ms |
24112 KB |
Output is correct |
62 |
Correct |
192 ms |
23420 KB |
Output is correct |
63 |
Correct |
174 ms |
17616 KB |
Output is correct |
64 |
Correct |
269 ms |
24136 KB |
Output is correct |
65 |
Correct |
166 ms |
24192 KB |
Output is correct |
66 |
Correct |
1 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 |
5 ms |
992 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
468 KB |
Output is correct |
73 |
Correct |
259 ms |
23448 KB |
Output is correct |
74 |
Correct |
288 ms |
21940 KB |
Output is correct |
75 |
Correct |
325 ms |
24300 KB |
Output is correct |
76 |
Correct |
400 ms |
24672 KB |
Output is correct |
77 |
Correct |
205 ms |
23768 KB |
Output is correct |
78 |
Correct |
96 ms |
14680 KB |
Output is correct |
79 |
Correct |
3 ms |
724 KB |
Output is correct |
80 |
Correct |
4 ms |
984 KB |
Output is correct |
81 |
Correct |
3 ms |
852 KB |
Output is correct |
82 |
Correct |
3 ms |
980 KB |
Output is correct |
83 |
Correct |
344 ms |
25180 KB |
Output is correct |
84 |
Correct |
446 ms |
25152 KB |
Output is correct |
85 |
Correct |
429 ms |
24596 KB |
Output is correct |
86 |
Correct |
459 ms |
25440 KB |
Output is correct |
87 |
Correct |
243 ms |
25164 KB |
Output is correct |
88 |
Correct |
332 ms |
25696 KB |
Output is correct |
89 |
Correct |
367 ms |
25316 KB |
Output is correct |
90 |
Correct |
352 ms |
26984 KB |
Output is correct |
91 |
Correct |
371 ms |
24784 KB |
Output is correct |
92 |
Correct |
356 ms |
24892 KB |
Output is correct |
93 |
Correct |
402 ms |
25944 KB |
Output is correct |
94 |
Correct |
406 ms |
26008 KB |
Output is correct |
95 |
Correct |
272 ms |
27012 KB |
Output is correct |
96 |
Correct |
208 ms |
26704 KB |
Output is correct |
97 |
Correct |
166 ms |
25736 KB |
Output is correct |
98 |
Correct |
120 ms |
25676 KB |
Output is correct |
99 |
Correct |
143 ms |
25676 KB |
Output is correct |