#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std ;
const int N = 15e4, NS = 4e3 ;
bool flag1, flag2, flag3 ;
int n, ans = -1, x[N + 1], y[N + 1], z[N + 1] ;
set<pair<int, pair<int, int>>> s ;
vector<pair<int, pair<int, int>>> v ;
int mx[2 * NS + 1][2 * NS + 1], num[2 * NS + 1][2 * NS + 1], kol = 0 ;
int func(int i, int j, int q)
{
if(x[i] > x[j] && x[i] > x[q] && y[j] > y[i] && y[j] > y[q] && z[i] < z[q] && z[j] < z[q])
return x[i] + y[j] + z[q] ;
else
return -1 ;
}
int func1(int i, int j, int q)
{
if(v[i].fi > v[j].fi && v[i].fi > v[q].fi && v[j].se.fi > v[i].se.fi && v[j].se.fi > v[q].se.fi && v[i].se.se < v[q].se.se && v[j].se.se < v[q].se.se)
return v[i].fi + v[j].se.fi + v[q].se.se ;
else
return -1 ;
}
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
cin >> n ;
for(int i = 1 ; i <= n ; i++)
{
cin >> x[i] >> y[i] >> z[i] ;
if(x[i] > 5 || y[i] > 5 || z[i] > 5)flag1 = 1 ;
if(x[i] > 20 || y[i] > 20 || z[i] > 20)flag2 = 1 ;
if(x[i] > 4000 || y[i] > 4000 || z[i] > 4000)flag3 = 1 ;
s.insert({x[i], {y[i], z[i]}}) ;
}
if(n <= 4000)
{
set<int> s1 ;
map<int, int> mp, ob ;
for(int i = 1 ; i <= n ; i++)
{
s1.insert(x[i]) ;
s1.insert(y[i]) ;
}
for(int i : s1)
kol++, mp[i] = kol ;
for(int i = 1 ; i <= n ; i++)
{
ob[mp[x[i]]] = x[i] ;
ob[mp[y[i]]] = y[i] ;
x[i] = mp[x[i]] ;
y[i] = mp[y[i]] ;
num[x[i]][y[i]] = z[i] ;
}
for(int i = 1 ; i <= 2 * n ; i++)
{
int now = 0 ;
for(int j = 1 ; j <= 2 * n ; j++)
{
now = max(now, num[i][j]) ;
mx[i][j] = max(now, mx[i - 1][j]) ;
}
}
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= n ; j++)
{
if(x[i] <= x[j] || y[j] <= y[i] || mx[x[i] - 1][y[j] - 1] <= max(z[i], z[j]))
continue ;
ans = max(ans, ob[x[i]] + ob[y[j]] + mx[x[i] - 1][y[j] - 1]) ;
}
cout << ans << '\n' ;
return 0 ;
}
if(!flag3)
{
}
if(!flag2)
{
for(auto i : s)
v.push_back(i) ;
for(int i = 1 ; i <= 20 ; i++)
for(int j = 1 ; j <= 20 ; j++)
for(int q = 1 ; q <= 20 ; q++)
{
bool fl1 = 0, fl2 = 0, fl3 = 0 ;
for(auto now : v)
{
if(now.fi == i && now.se.fi < j && now.se.se < q)fl1 = 1 ;
if(now.fi < i && now.se.fi == j && now.se.se < q)fl2 = 1 ;
if(now.fi < i && now.se.fi < j && now.se.se == q)fl3 = 1 ;
}
if(fl1 && fl2 && fl3)
ans = max(ans, i + j + q) ;
}
cout << ans ;
return 0 ;
}
if(n <= 300)
{
for(int i = 1 ; i <= n ; i++)
for(int j = 1 ; j <= n ; j++)
{
if(i == j)
continue ;
for(int q = 1 ; q <= n ; q++)
{
if(j == q || i == q)
continue ;
ans = max(ans, func(i, j, q)) ;
}
}
cout << ans << '\n' ;
return 0 ;
}
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
368 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
5472 KB |
Output is correct |
15 |
Correct |
3 ms |
3668 KB |
Output is correct |
16 |
Correct |
3 ms |
4392 KB |
Output is correct |
17 |
Correct |
3 ms |
4820 KB |
Output is correct |
18 |
Correct |
4 ms |
4436 KB |
Output is correct |
19 |
Correct |
4 ms |
4436 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
3 ms |
4436 KB |
Output is correct |
22 |
Correct |
3 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
3 ms |
4564 KB |
Output is correct |
25 |
Correct |
4 ms |
4564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
368 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
5472 KB |
Output is correct |
15 |
Correct |
3 ms |
3668 KB |
Output is correct |
16 |
Correct |
3 ms |
4392 KB |
Output is correct |
17 |
Correct |
3 ms |
4820 KB |
Output is correct |
18 |
Correct |
4 ms |
4436 KB |
Output is correct |
19 |
Correct |
4 ms |
4436 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
3 ms |
4436 KB |
Output is correct |
22 |
Correct |
3 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
3 ms |
4564 KB |
Output is correct |
25 |
Correct |
4 ms |
4564 KB |
Output is correct |
26 |
Correct |
701 ms |
268736 KB |
Output is correct |
27 |
Correct |
505 ms |
264564 KB |
Output is correct |
28 |
Correct |
388 ms |
265256 KB |
Output is correct |
29 |
Correct |
273 ms |
261580 KB |
Output is correct |
30 |
Correct |
147 ms |
142204 KB |
Output is correct |
31 |
Correct |
459 ms |
257808 KB |
Output is correct |
32 |
Correct |
265 ms |
252928 KB |
Output is correct |
33 |
Correct |
192 ms |
244784 KB |
Output is correct |
34 |
Correct |
244 ms |
268352 KB |
Output is correct |
35 |
Correct |
15 ms |
21656 KB |
Output is correct |
36 |
Correct |
17 ms |
21588 KB |
Output is correct |
37 |
Correct |
195 ms |
257136 KB |
Output is correct |
38 |
Correct |
191 ms |
257128 KB |
Output is correct |
39 |
Correct |
96 ms |
79492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
30 ms |
2008 KB |
Output is correct |
12 |
Correct |
16 ms |
1444 KB |
Output is correct |
13 |
Correct |
29 ms |
1752 KB |
Output is correct |
14 |
Correct |
24 ms |
1976 KB |
Output is correct |
15 |
Correct |
26 ms |
1948 KB |
Output is correct |
16 |
Correct |
20 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
30 ms |
2008 KB |
Output is correct |
12 |
Correct |
16 ms |
1444 KB |
Output is correct |
13 |
Correct |
29 ms |
1752 KB |
Output is correct |
14 |
Correct |
24 ms |
1976 KB |
Output is correct |
15 |
Correct |
26 ms |
1948 KB |
Output is correct |
16 |
Correct |
20 ms |
2028 KB |
Output is correct |
17 |
Correct |
1 ms |
360 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
109 ms |
79520 KB |
Output is correct |
22 |
Correct |
116 ms |
2756 KB |
Output is correct |
23 |
Correct |
44 ms |
2164 KB |
Output is correct |
24 |
Correct |
49 ms |
1684 KB |
Output is correct |
25 |
Correct |
38 ms |
2156 KB |
Output is correct |
26 |
Correct |
23 ms |
2008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
30 ms |
2008 KB |
Output is correct |
12 |
Correct |
16 ms |
1444 KB |
Output is correct |
13 |
Correct |
29 ms |
1752 KB |
Output is correct |
14 |
Correct |
24 ms |
1976 KB |
Output is correct |
15 |
Correct |
26 ms |
1948 KB |
Output is correct |
16 |
Correct |
20 ms |
2028 KB |
Output is correct |
17 |
Correct |
1 ms |
360 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
109 ms |
79520 KB |
Output is correct |
22 |
Correct |
116 ms |
2756 KB |
Output is correct |
23 |
Correct |
44 ms |
2164 KB |
Output is correct |
24 |
Correct |
49 ms |
1684 KB |
Output is correct |
25 |
Correct |
38 ms |
2156 KB |
Output is correct |
26 |
Correct |
23 ms |
2008 KB |
Output is correct |
27 |
Correct |
5 ms |
4436 KB |
Output is correct |
28 |
Correct |
4 ms |
4452 KB |
Output is correct |
29 |
Correct |
4 ms |
4564 KB |
Output is correct |
30 |
Correct |
3 ms |
4564 KB |
Output is correct |
31 |
Correct |
246 ms |
252912 KB |
Output is correct |
32 |
Correct |
14 ms |
21612 KB |
Output is correct |
33 |
Correct |
16 ms |
21572 KB |
Output is correct |
34 |
Incorrect |
79 ms |
10880 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
30 ms |
2008 KB |
Output is correct |
12 |
Correct |
16 ms |
1444 KB |
Output is correct |
13 |
Correct |
29 ms |
1752 KB |
Output is correct |
14 |
Correct |
24 ms |
1976 KB |
Output is correct |
15 |
Correct |
26 ms |
1948 KB |
Output is correct |
16 |
Correct |
20 ms |
2028 KB |
Output is correct |
17 |
Correct |
1 ms |
360 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
109 ms |
79520 KB |
Output is correct |
22 |
Correct |
116 ms |
2756 KB |
Output is correct |
23 |
Correct |
44 ms |
2164 KB |
Output is correct |
24 |
Correct |
49 ms |
1684 KB |
Output is correct |
25 |
Correct |
38 ms |
2156 KB |
Output is correct |
26 |
Correct |
23 ms |
2008 KB |
Output is correct |
27 |
Correct |
5 ms |
4436 KB |
Output is correct |
28 |
Correct |
4 ms |
4452 KB |
Output is correct |
29 |
Correct |
4 ms |
4564 KB |
Output is correct |
30 |
Correct |
3 ms |
4564 KB |
Output is correct |
31 |
Correct |
246 ms |
252912 KB |
Output is correct |
32 |
Correct |
14 ms |
21612 KB |
Output is correct |
33 |
Correct |
16 ms |
21572 KB |
Output is correct |
34 |
Incorrect |
79 ms |
10880 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
368 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
6 ms |
5472 KB |
Output is correct |
15 |
Correct |
3 ms |
3668 KB |
Output is correct |
16 |
Correct |
3 ms |
4392 KB |
Output is correct |
17 |
Correct |
3 ms |
4820 KB |
Output is correct |
18 |
Correct |
4 ms |
4436 KB |
Output is correct |
19 |
Correct |
4 ms |
4436 KB |
Output is correct |
20 |
Correct |
4 ms |
4180 KB |
Output is correct |
21 |
Correct |
3 ms |
4436 KB |
Output is correct |
22 |
Correct |
3 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
3 ms |
4564 KB |
Output is correct |
25 |
Correct |
4 ms |
4564 KB |
Output is correct |
26 |
Correct |
701 ms |
268736 KB |
Output is correct |
27 |
Correct |
505 ms |
264564 KB |
Output is correct |
28 |
Correct |
388 ms |
265256 KB |
Output is correct |
29 |
Correct |
273 ms |
261580 KB |
Output is correct |
30 |
Correct |
147 ms |
142204 KB |
Output is correct |
31 |
Correct |
459 ms |
257808 KB |
Output is correct |
32 |
Correct |
265 ms |
252928 KB |
Output is correct |
33 |
Correct |
192 ms |
244784 KB |
Output is correct |
34 |
Correct |
244 ms |
268352 KB |
Output is correct |
35 |
Correct |
15 ms |
21656 KB |
Output is correct |
36 |
Correct |
17 ms |
21588 KB |
Output is correct |
37 |
Correct |
195 ms |
257136 KB |
Output is correct |
38 |
Correct |
191 ms |
257128 KB |
Output is correct |
39 |
Correct |
96 ms |
79492 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
30 ms |
2008 KB |
Output is correct |
51 |
Correct |
16 ms |
1444 KB |
Output is correct |
52 |
Correct |
29 ms |
1752 KB |
Output is correct |
53 |
Correct |
24 ms |
1976 KB |
Output is correct |
54 |
Correct |
26 ms |
1948 KB |
Output is correct |
55 |
Correct |
20 ms |
2028 KB |
Output is correct |
56 |
Correct |
1 ms |
360 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
4 ms |
4180 KB |
Output is correct |
60 |
Correct |
109 ms |
79520 KB |
Output is correct |
61 |
Correct |
116 ms |
2756 KB |
Output is correct |
62 |
Correct |
44 ms |
2164 KB |
Output is correct |
63 |
Correct |
49 ms |
1684 KB |
Output is correct |
64 |
Correct |
38 ms |
2156 KB |
Output is correct |
65 |
Correct |
23 ms |
2008 KB |
Output is correct |
66 |
Correct |
5 ms |
4436 KB |
Output is correct |
67 |
Correct |
4 ms |
4452 KB |
Output is correct |
68 |
Correct |
4 ms |
4564 KB |
Output is correct |
69 |
Correct |
3 ms |
4564 KB |
Output is correct |
70 |
Correct |
246 ms |
252912 KB |
Output is correct |
71 |
Correct |
14 ms |
21612 KB |
Output is correct |
72 |
Correct |
16 ms |
21572 KB |
Output is correct |
73 |
Incorrect |
79 ms |
10880 KB |
Output isn't correct |
74 |
Halted |
0 ms |
0 KB |
- |