#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
const int INF=1e9;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<pair<int,pii>> v(n);
for(int i=0;i<n;i++){
cin>>v[i].x>>v[i].y.x>>v[i].y.y;
}
sort(all(v));
vector<pii> q;
set<pii> s,c,c1;
int ans=-1;
for(int i=0;i<n;i++){
pii t=v[i].y;
if(i>0&&v[i].x>v[i-1].x){
//random_shuffle(all(q));
for(auto t:q){
auto it=c.lower_bound({t.x,0});
if(it!=c.begin()&&(*prev(it)).y>t.y){
continue;
}
c.insert(t);
it=c.lower_bound(t);
it++;
while(it!=c.end()){
if(t.y>=(*it).y){
c.erase(it);
it=c.lower_bound(t);
it++;
}
else{
break;
}
}
}
for(auto t:q){
auto it=c.lower_bound({t.x,0});
int tmp=-1;
if(it!=c.begin()&&(*prev(it)).y>t.y){
tmp=(*prev(it)).y;
}
if(tmp==-1){
continue;
}
//cout<<tmp<<endl;
s.insert({t.x,tmp});
}
for(auto t:q){
swap(t.x,t.y);
auto it=c1.lower_bound({t.x,0});
if(it!=c1.begin()&&(*prev(it)).y>t.y){
continue;
}
c1.insert(t);
it=c1.lower_bound(t);
it++;
while(it!=c1.end()){
if(t.y>=(*it).y){
c1.erase(it);
it=c1.lower_bound(t);
it++;
}
else{
break;
}
}
}
for(auto t:q){
swap(t.x,t.y);
auto it=c1.lower_bound({t.x,0});
int tmp=-1;
if(it!=c1.begin()&&(*prev(it)).y>t.y){
tmp=(*prev(it)).y;
}
if(tmp==-1){
continue;
}
s.insert({tmp,t.x});
}
while(s.size()>1){
s.erase(s.begin());
}
q.clear();
}
q.push_back(v[i].y);
auto it=s.upper_bound({t.x,INF});
if(it==s.end()||(*it).y<=t.y){
continue;
}
//cout<<v[i].x<<' '<<(*it).x<<' '<<(*it).y<<endl;
ans=max(ans,v[i].x+(*it).x+(*it).y);
}
/*for(auto e:c1){
cout<<e.x<<' '<<e.y<<endl;
}
for(auto e:s){
cout<<e.x<<' '<<e.y<<endl;
}*/
cout<<ans<<endl;
return 0;
}
/*
5
1 4 3
3 1 2
5 5 1
4 2 4
2 3 5
*/
# |
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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
332 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 |
324 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
332 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 |
324 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
4 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
544 KB |
Output is correct |
38 |
Correct |
3 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 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 |
316 KB |
Output is correct |
11 |
Correct |
39 ms |
2960 KB |
Output is correct |
12 |
Correct |
28 ms |
2288 KB |
Output is correct |
13 |
Correct |
31 ms |
2716 KB |
Output is correct |
14 |
Correct |
39 ms |
3160 KB |
Output is correct |
15 |
Correct |
33 ms |
3660 KB |
Output is correct |
16 |
Correct |
29 ms |
4684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 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 |
316 KB |
Output is correct |
11 |
Correct |
39 ms |
2960 KB |
Output is correct |
12 |
Correct |
28 ms |
2288 KB |
Output is correct |
13 |
Correct |
31 ms |
2716 KB |
Output is correct |
14 |
Correct |
39 ms |
3160 KB |
Output is correct |
15 |
Correct |
33 ms |
3660 KB |
Output is correct |
16 |
Correct |
29 ms |
4684 KB |
Output is correct |
17 |
Correct |
0 ms |
316 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
52 ms |
2596 KB |
Output is correct |
23 |
Correct |
51 ms |
2764 KB |
Output is correct |
24 |
Correct |
42 ms |
2152 KB |
Output is correct |
25 |
Correct |
56 ms |
2936 KB |
Output is correct |
26 |
Correct |
39 ms |
3716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 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 |
316 KB |
Output is correct |
11 |
Correct |
39 ms |
2960 KB |
Output is correct |
12 |
Correct |
28 ms |
2288 KB |
Output is correct |
13 |
Correct |
31 ms |
2716 KB |
Output is correct |
14 |
Correct |
39 ms |
3160 KB |
Output is correct |
15 |
Correct |
33 ms |
3660 KB |
Output is correct |
16 |
Correct |
29 ms |
4684 KB |
Output is correct |
17 |
Correct |
0 ms |
316 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
52 ms |
2596 KB |
Output is correct |
23 |
Correct |
51 ms |
2764 KB |
Output is correct |
24 |
Correct |
42 ms |
2152 KB |
Output is correct |
25 |
Correct |
56 ms |
2936 KB |
Output is correct |
26 |
Correct |
39 ms |
3716 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
316 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
79 ms |
2560 KB |
Output is correct |
35 |
Correct |
82 ms |
2496 KB |
Output is correct |
36 |
Correct |
87 ms |
2628 KB |
Output is correct |
37 |
Correct |
92 ms |
2596 KB |
Output is correct |
38 |
Correct |
40 ms |
3660 KB |
Output is correct |
39 |
Correct |
20 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 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 |
316 KB |
Output is correct |
11 |
Correct |
39 ms |
2960 KB |
Output is correct |
12 |
Correct |
28 ms |
2288 KB |
Output is correct |
13 |
Correct |
31 ms |
2716 KB |
Output is correct |
14 |
Correct |
39 ms |
3160 KB |
Output is correct |
15 |
Correct |
33 ms |
3660 KB |
Output is correct |
16 |
Correct |
29 ms |
4684 KB |
Output is correct |
17 |
Correct |
0 ms |
316 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
52 ms |
2596 KB |
Output is correct |
23 |
Correct |
51 ms |
2764 KB |
Output is correct |
24 |
Correct |
42 ms |
2152 KB |
Output is correct |
25 |
Correct |
56 ms |
2936 KB |
Output is correct |
26 |
Correct |
39 ms |
3716 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
316 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
79 ms |
2560 KB |
Output is correct |
35 |
Correct |
82 ms |
2496 KB |
Output is correct |
36 |
Correct |
87 ms |
2628 KB |
Output is correct |
37 |
Correct |
92 ms |
2596 KB |
Output is correct |
38 |
Correct |
40 ms |
3660 KB |
Output is correct |
39 |
Correct |
20 ms |
3020 KB |
Output is correct |
40 |
Correct |
3 ms |
336 KB |
Output is correct |
41 |
Correct |
3 ms |
340 KB |
Output is correct |
42 |
Correct |
3 ms |
584 KB |
Output is correct |
43 |
Correct |
3 ms |
596 KB |
Output is correct |
44 |
Correct |
86 ms |
4148 KB |
Output is correct |
45 |
Correct |
125 ms |
4368 KB |
Output is correct |
46 |
Correct |
119 ms |
4384 KB |
Output is correct |
47 |
Correct |
127 ms |
4504 KB |
Output is correct |
48 |
Correct |
49 ms |
5192 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
332 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 |
324 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
4 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
544 KB |
Output is correct |
38 |
Correct |
3 ms |
596 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 |
320 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
320 KB |
Output is correct |
45 |
Correct |
1 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 |
316 KB |
Output is correct |
50 |
Correct |
39 ms |
2960 KB |
Output is correct |
51 |
Correct |
28 ms |
2288 KB |
Output is correct |
52 |
Correct |
31 ms |
2716 KB |
Output is correct |
53 |
Correct |
39 ms |
3160 KB |
Output is correct |
54 |
Correct |
33 ms |
3660 KB |
Output is correct |
55 |
Correct |
29 ms |
4684 KB |
Output is correct |
56 |
Correct |
0 ms |
316 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
312 KB |
Output is correct |
60 |
Correct |
2 ms |
340 KB |
Output is correct |
61 |
Correct |
52 ms |
2596 KB |
Output is correct |
62 |
Correct |
51 ms |
2764 KB |
Output is correct |
63 |
Correct |
42 ms |
2152 KB |
Output is correct |
64 |
Correct |
56 ms |
2936 KB |
Output is correct |
65 |
Correct |
39 ms |
3716 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
1 ms |
316 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
316 KB |
Output is correct |
70 |
Correct |
3 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
79 ms |
2560 KB |
Output is correct |
74 |
Correct |
82 ms |
2496 KB |
Output is correct |
75 |
Correct |
87 ms |
2628 KB |
Output is correct |
76 |
Correct |
92 ms |
2596 KB |
Output is correct |
77 |
Correct |
40 ms |
3660 KB |
Output is correct |
78 |
Correct |
20 ms |
3020 KB |
Output is correct |
79 |
Correct |
3 ms |
336 KB |
Output is correct |
80 |
Correct |
3 ms |
340 KB |
Output is correct |
81 |
Correct |
3 ms |
584 KB |
Output is correct |
82 |
Correct |
3 ms |
596 KB |
Output is correct |
83 |
Correct |
86 ms |
4148 KB |
Output is correct |
84 |
Correct |
125 ms |
4368 KB |
Output is correct |
85 |
Correct |
119 ms |
4384 KB |
Output is correct |
86 |
Correct |
127 ms |
4504 KB |
Output is correct |
87 |
Correct |
49 ms |
5192 KB |
Output is correct |
88 |
Correct |
75 ms |
5904 KB |
Output is correct |
89 |
Correct |
133 ms |
7328 KB |
Output is correct |
90 |
Correct |
93 ms |
6292 KB |
Output is correct |
91 |
Correct |
161 ms |
7132 KB |
Output is correct |
92 |
Correct |
114 ms |
5152 KB |
Output is correct |
93 |
Correct |
144 ms |
6884 KB |
Output is correct |
94 |
Correct |
159 ms |
6672 KB |
Output is correct |
95 |
Correct |
58 ms |
6988 KB |
Output is correct |
96 |
Correct |
219 ms |
19996 KB |
Output is correct |
97 |
Correct |
50 ms |
8264 KB |
Output is correct |
98 |
Correct |
139 ms |
13960 KB |
Output is correct |
99 |
Correct |
150 ms |
14008 KB |
Output is correct |