#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define F(i,a,b) for(ll i=a;i<=b;i++)
const ll maxn=3e5+10 ;
const ll base=3e18;
const ll mod= 1e9+7 ;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
/// have medal in APIO
/// goal 2/8
ll n;
pair<ll,pll> a[maxn];
set<pll> st;
set<pll> st1;
ll mx=-1;
void add(ll x,ll y)
{
auto it1=st.upper_bound(make_pair(x,-base));
vector<pll> vt;
while (it1!=st.end()&&(*it1).ss<y)
{
mx=max(mx,(*it1).ff);
vt.pb(*it1);
it1++;
}
for (auto p:vt) st.erase(p);
vt.clear();
auto it=st1.upper_bound(make_pair(x,-base));
while (it!=st1.end()&&(*it).ss<=y)
{
vt.pb(*it);
it++;
}
for (auto p:vt) st1.erase(p);
it=st1.upper_bound(make_pair(x,base));
if (it==st1.begin())
{
st1.insert(make_pair(x,y));
}
else
{
it--;
if ((*it).ss<y) st1.insert(make_pair(x,y));
}
}
/*
4
5 6 1
7 5 1
5 5 2
4 7 6
*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("test.inp","r"))
{
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
cin>> n;
for (int i=1; i<=n; i++)
{
cin>> a[i].ff>> a[i].ss.ff>>a[i].ss.ss;
}
sort(a+1,a+n+1);
ll ans=-1;
for (int i=1; i<=n; i++)
{
ll j=i;
while (j<=n&&a[j].ff==a[i].ff)
j++ ;
j--;
auto it=st1.upper_bound(make_pair(mx,base));
if (it!=st1.begin())
{
it--;
ll vals=(*it).ss;
for (int t=i;t<=j;t++)
{
if (a[t].ss.ff<mx&&a[t].ss.ss<vals)
{
ans=max(ans,mx+vals+a[t].ff);
}
}
}
/* if (i==4)
{
for (auto p:st) cout <<p.ff<<" "<<p.ss<<" chk1"<<endl;
for (auto p:st1) cout <<p.ff<<" "<<p.ss<<" chk2"<<endl;
cout <<mx<<endl;
}*/
for (int t=i;t<=j;t++)
{
ll x=a[t].ss.ff;
ll y=a[t].ss.ss;
add(x+1,y);
auto it=st1.upper_bound(make_pair(x,base));
bool chk=false;
if (it!=st1.begin())
{
it--;
if ((*it).ss>y)
{
chk=true;
mx=max(mx,x);
}
}
if (!chk)
{
auto it=st.upper_bound(make_pair(x,-base));
if (it!=st.end()&&(*it).ss<=y)
{
}
else
{
it=st.upper_bound(make_pair(x,base));
vector<pll> vt;
if (it!=st.begin())
{
it--;
while (1)
{
if ((*it).ss>=y)
{
vt.pb(*it);
if (it==st.begin()) break;
else it--;
}
else break;
}
}
for (auto p:vt) st.erase(p);
st.insert(make_pair(x,y));
}
}
}
i=j;
}
cout <<ans<<endl;
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen("test.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
team.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
332 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 |
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 |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 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 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
332 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 |
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 |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
440 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
3 ms |
476 KB |
Output is correct |
29 |
Correct |
4 ms |
444 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
528 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
328 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 |
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 |
1 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 |
36 ms |
4328 KB |
Output is correct |
12 |
Correct |
25 ms |
3036 KB |
Output is correct |
13 |
Correct |
31 ms |
3912 KB |
Output is correct |
14 |
Correct |
40 ms |
4604 KB |
Output is correct |
15 |
Correct |
36 ms |
4276 KB |
Output is correct |
16 |
Correct |
39 ms |
4440 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 |
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 |
1 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 |
36 ms |
4328 KB |
Output is correct |
12 |
Correct |
25 ms |
3036 KB |
Output is correct |
13 |
Correct |
31 ms |
3912 KB |
Output is correct |
14 |
Correct |
40 ms |
4604 KB |
Output is correct |
15 |
Correct |
36 ms |
4276 KB |
Output is correct |
16 |
Correct |
39 ms |
4440 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
48 ms |
4584 KB |
Output is correct |
23 |
Correct |
42 ms |
4556 KB |
Output is correct |
24 |
Correct |
32 ms |
3412 KB |
Output is correct |
25 |
Correct |
44 ms |
4820 KB |
Output is correct |
26 |
Correct |
37 ms |
4672 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 |
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 |
1 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 |
36 ms |
4328 KB |
Output is correct |
12 |
Correct |
25 ms |
3036 KB |
Output is correct |
13 |
Correct |
31 ms |
3912 KB |
Output is correct |
14 |
Correct |
40 ms |
4604 KB |
Output is correct |
15 |
Correct |
36 ms |
4276 KB |
Output is correct |
16 |
Correct |
39 ms |
4440 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
48 ms |
4584 KB |
Output is correct |
23 |
Correct |
42 ms |
4556 KB |
Output is correct |
24 |
Correct |
32 ms |
3412 KB |
Output is correct |
25 |
Correct |
44 ms |
4820 KB |
Output is correct |
26 |
Correct |
37 ms |
4672 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 |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
49 ms |
4944 KB |
Output is correct |
35 |
Correct |
51 ms |
4316 KB |
Output is correct |
36 |
Correct |
55 ms |
4884 KB |
Output is correct |
37 |
Correct |
60 ms |
5464 KB |
Output is correct |
38 |
Correct |
42 ms |
4864 KB |
Output is correct |
39 |
Correct |
23 ms |
3048 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 |
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 |
1 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 |
36 ms |
4328 KB |
Output is correct |
12 |
Correct |
25 ms |
3036 KB |
Output is correct |
13 |
Correct |
31 ms |
3912 KB |
Output is correct |
14 |
Correct |
40 ms |
4604 KB |
Output is correct |
15 |
Correct |
36 ms |
4276 KB |
Output is correct |
16 |
Correct |
39 ms |
4440 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
48 ms |
4584 KB |
Output is correct |
23 |
Correct |
42 ms |
4556 KB |
Output is correct |
24 |
Correct |
32 ms |
3412 KB |
Output is correct |
25 |
Correct |
44 ms |
4820 KB |
Output is correct |
26 |
Correct |
37 ms |
4672 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 |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
49 ms |
4944 KB |
Output is correct |
35 |
Correct |
51 ms |
4316 KB |
Output is correct |
36 |
Correct |
55 ms |
4884 KB |
Output is correct |
37 |
Correct |
60 ms |
5464 KB |
Output is correct |
38 |
Correct |
42 ms |
4864 KB |
Output is correct |
39 |
Correct |
23 ms |
3048 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
396 KB |
Output is correct |
42 |
Correct |
3 ms |
468 KB |
Output is correct |
43 |
Correct |
3 ms |
468 KB |
Output is correct |
44 |
Correct |
56 ms |
5844 KB |
Output is correct |
45 |
Correct |
76 ms |
5880 KB |
Output is correct |
46 |
Correct |
78 ms |
5468 KB |
Output is correct |
47 |
Correct |
79 ms |
6060 KB |
Output is correct |
48 |
Correct |
49 ms |
5708 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 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
332 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 |
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 |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
440 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
3 ms |
476 KB |
Output is correct |
29 |
Correct |
4 ms |
444 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
528 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
328 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 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 |
1 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 |
36 ms |
4328 KB |
Output is correct |
51 |
Correct |
25 ms |
3036 KB |
Output is correct |
52 |
Correct |
31 ms |
3912 KB |
Output is correct |
53 |
Correct |
40 ms |
4604 KB |
Output is correct |
54 |
Correct |
36 ms |
4276 KB |
Output is correct |
55 |
Correct |
39 ms |
4440 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
328 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
48 ms |
4584 KB |
Output is correct |
62 |
Correct |
42 ms |
4556 KB |
Output is correct |
63 |
Correct |
32 ms |
3412 KB |
Output is correct |
64 |
Correct |
44 ms |
4820 KB |
Output is correct |
65 |
Correct |
37 ms |
4672 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 |
2 ms |
460 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
49 ms |
4944 KB |
Output is correct |
74 |
Correct |
51 ms |
4316 KB |
Output is correct |
75 |
Correct |
55 ms |
4884 KB |
Output is correct |
76 |
Correct |
60 ms |
5464 KB |
Output is correct |
77 |
Correct |
42 ms |
4864 KB |
Output is correct |
78 |
Correct |
23 ms |
3048 KB |
Output is correct |
79 |
Correct |
2 ms |
468 KB |
Output is correct |
80 |
Correct |
2 ms |
396 KB |
Output is correct |
81 |
Correct |
3 ms |
468 KB |
Output is correct |
82 |
Correct |
3 ms |
468 KB |
Output is correct |
83 |
Correct |
56 ms |
5844 KB |
Output is correct |
84 |
Correct |
76 ms |
5880 KB |
Output is correct |
85 |
Correct |
78 ms |
5468 KB |
Output is correct |
86 |
Correct |
79 ms |
6060 KB |
Output is correct |
87 |
Correct |
49 ms |
5708 KB |
Output is correct |
88 |
Correct |
63 ms |
6348 KB |
Output is correct |
89 |
Correct |
114 ms |
7520 KB |
Output is correct |
90 |
Correct |
72 ms |
7876 KB |
Output is correct |
91 |
Correct |
143 ms |
6772 KB |
Output is correct |
92 |
Correct |
78 ms |
5956 KB |
Output is correct |
93 |
Correct |
124 ms |
8748 KB |
Output is correct |
94 |
Correct |
124 ms |
8180 KB |
Output is correct |
95 |
Correct |
62 ms |
7548 KB |
Output is correct |
96 |
Correct |
299 ms |
26116 KB |
Output is correct |
97 |
Correct |
58 ms |
6396 KB |
Output is correct |
98 |
Correct |
159 ms |
9416 KB |
Output is correct |
99 |
Correct |
176 ms |
9408 KB |
Output is correct |