#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
set<pll> S = {{-2, -1}, {-1, -2}};
ll X = -1, Y = -1;
auto p = ++S.begin();
void add(ll x, ll y)
{
if (x < X) {
S.insert({x, y});
Y = max(Y, y);
} else if (x == X && y <= p->second) {
S.insert({x, y});
} else {
auto p2 = S.insert({x, y}).first;
auto p2l = p2; --p2l;
if (p2l->second > p2->second || Y > p2->second) {
Y = max(Y, p2l->second);
X = p2->first;
p = p2;
} else {
auto p2r = p2; ++p2r;
if (p2r != S.end() && (p2->second > p2r->second || Y > p2r->second)) {
Y = max(Y, p2->second);
X = p2r->first;
p = p2r;
}
}
}
for (;;) {
auto p2 = p; ++p2;
ll newY = max(Y, p->second);
if (p2 == S.end() || p2->second >= newY)
break;
p = p2;
Y = newY;
X = p->first;
}
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n;
cin >> n;
map<ll, vector<pll>> mp;
Loop (i,0,n) {
ll x, y, z;
cin >> x >> y >> z;
mp[z].push_back({x, y});
}
ll ans = -1;
for (auto &[z, vec] : mp) {
for (auto [x, y] : vec) {
if (X > x && Y > y)
ans = max(ans, X+Y+z);
}
for (auto [x, y] : vec)
add(x, y);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
324 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 |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
324 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 |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
3 ms |
1108 KB |
Output is correct |
27 |
Correct |
3 ms |
844 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
844 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
696 KB |
Output is correct |
34 |
Correct |
3 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
2 ms |
712 KB |
Output is correct |
38 |
Correct |
2 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
26 ms |
3712 KB |
Output is correct |
12 |
Correct |
17 ms |
2752 KB |
Output is correct |
13 |
Correct |
21 ms |
3164 KB |
Output is correct |
14 |
Correct |
33 ms |
5064 KB |
Output is correct |
15 |
Correct |
30 ms |
3916 KB |
Output is correct |
16 |
Correct |
26 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
26 ms |
3712 KB |
Output is correct |
12 |
Correct |
17 ms |
2752 KB |
Output is correct |
13 |
Correct |
21 ms |
3164 KB |
Output is correct |
14 |
Correct |
33 ms |
5064 KB |
Output is correct |
15 |
Correct |
30 ms |
3916 KB |
Output is correct |
16 |
Correct |
26 ms |
5452 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
33 ms |
4304 KB |
Output is correct |
23 |
Correct |
29 ms |
3988 KB |
Output is correct |
24 |
Correct |
22 ms |
3284 KB |
Output is correct |
25 |
Correct |
32 ms |
4804 KB |
Output is correct |
26 |
Correct |
27 ms |
3808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
26 ms |
3712 KB |
Output is correct |
12 |
Correct |
17 ms |
2752 KB |
Output is correct |
13 |
Correct |
21 ms |
3164 KB |
Output is correct |
14 |
Correct |
33 ms |
5064 KB |
Output is correct |
15 |
Correct |
30 ms |
3916 KB |
Output is correct |
16 |
Correct |
26 ms |
5452 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
33 ms |
4304 KB |
Output is correct |
23 |
Correct |
29 ms |
3988 KB |
Output is correct |
24 |
Correct |
22 ms |
3284 KB |
Output is correct |
25 |
Correct |
32 ms |
4804 KB |
Output is correct |
26 |
Correct |
27 ms |
3808 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 |
3 ms |
588 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
64 ms |
8772 KB |
Output is correct |
35 |
Correct |
54 ms |
8288 KB |
Output is correct |
36 |
Correct |
69 ms |
8112 KB |
Output is correct |
37 |
Correct |
49 ms |
7664 KB |
Output is correct |
38 |
Correct |
30 ms |
4424 KB |
Output is correct |
39 |
Correct |
22 ms |
3756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
26 ms |
3712 KB |
Output is correct |
12 |
Correct |
17 ms |
2752 KB |
Output is correct |
13 |
Correct |
21 ms |
3164 KB |
Output is correct |
14 |
Correct |
33 ms |
5064 KB |
Output is correct |
15 |
Correct |
30 ms |
3916 KB |
Output is correct |
16 |
Correct |
26 ms |
5452 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
33 ms |
4304 KB |
Output is correct |
23 |
Correct |
29 ms |
3988 KB |
Output is correct |
24 |
Correct |
22 ms |
3284 KB |
Output is correct |
25 |
Correct |
32 ms |
4804 KB |
Output is correct |
26 |
Correct |
27 ms |
3808 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 |
3 ms |
588 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
64 ms |
8772 KB |
Output is correct |
35 |
Correct |
54 ms |
8288 KB |
Output is correct |
36 |
Correct |
69 ms |
8112 KB |
Output is correct |
37 |
Correct |
49 ms |
7664 KB |
Output is correct |
38 |
Correct |
30 ms |
4424 KB |
Output is correct |
39 |
Correct |
22 ms |
3756 KB |
Output is correct |
40 |
Correct |
2 ms |
596 KB |
Output is correct |
41 |
Correct |
3 ms |
724 KB |
Output is correct |
42 |
Correct |
2 ms |
716 KB |
Output is correct |
43 |
Correct |
2 ms |
724 KB |
Output is correct |
44 |
Correct |
95 ms |
15696 KB |
Output is correct |
45 |
Correct |
77 ms |
12784 KB |
Output is correct |
46 |
Correct |
83 ms |
13708 KB |
Output is correct |
47 |
Correct |
83 ms |
12704 KB |
Output is correct |
48 |
Correct |
40 ms |
5380 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
324 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 |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
3 ms |
1108 KB |
Output is correct |
27 |
Correct |
3 ms |
844 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
844 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
696 KB |
Output is correct |
34 |
Correct |
3 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
2 ms |
712 KB |
Output is correct |
38 |
Correct |
2 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
320 KB |
Output is correct |
41 |
Correct |
1 ms |
316 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
26 ms |
3712 KB |
Output is correct |
51 |
Correct |
17 ms |
2752 KB |
Output is correct |
52 |
Correct |
21 ms |
3164 KB |
Output is correct |
53 |
Correct |
33 ms |
5064 KB |
Output is correct |
54 |
Correct |
30 ms |
3916 KB |
Output is correct |
55 |
Correct |
26 ms |
5452 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
0 ms |
316 KB |
Output is correct |
58 |
Correct |
1 ms |
324 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
328 KB |
Output is correct |
61 |
Correct |
33 ms |
4304 KB |
Output is correct |
62 |
Correct |
29 ms |
3988 KB |
Output is correct |
63 |
Correct |
22 ms |
3284 KB |
Output is correct |
64 |
Correct |
32 ms |
4804 KB |
Output is correct |
65 |
Correct |
27 ms |
3808 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 |
3 ms |
588 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
64 ms |
8772 KB |
Output is correct |
74 |
Correct |
54 ms |
8288 KB |
Output is correct |
75 |
Correct |
69 ms |
8112 KB |
Output is correct |
76 |
Correct |
49 ms |
7664 KB |
Output is correct |
77 |
Correct |
30 ms |
4424 KB |
Output is correct |
78 |
Correct |
22 ms |
3756 KB |
Output is correct |
79 |
Correct |
2 ms |
596 KB |
Output is correct |
80 |
Correct |
3 ms |
724 KB |
Output is correct |
81 |
Correct |
2 ms |
716 KB |
Output is correct |
82 |
Correct |
2 ms |
724 KB |
Output is correct |
83 |
Correct |
95 ms |
15696 KB |
Output is correct |
84 |
Correct |
77 ms |
12784 KB |
Output is correct |
85 |
Correct |
83 ms |
13708 KB |
Output is correct |
86 |
Correct |
83 ms |
12704 KB |
Output is correct |
87 |
Correct |
40 ms |
5380 KB |
Output is correct |
88 |
Correct |
196 ms |
29976 KB |
Output is correct |
89 |
Correct |
177 ms |
23544 KB |
Output is correct |
90 |
Correct |
157 ms |
24812 KB |
Output is correct |
91 |
Correct |
148 ms |
22008 KB |
Output is correct |
92 |
Correct |
124 ms |
17896 KB |
Output is correct |
93 |
Correct |
162 ms |
22900 KB |
Output is correct |
94 |
Correct |
114 ms |
19276 KB |
Output is correct |
95 |
Correct |
75 ms |
14600 KB |
Output is correct |
96 |
Correct |
168 ms |
30004 KB |
Output is correct |
97 |
Correct |
42 ms |
8240 KB |
Output is correct |
98 |
Correct |
74 ms |
16640 KB |
Output is correct |
99 |
Correct |
74 ms |
16600 KB |
Output is correct |