#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));
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("t.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);
}
}
}
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:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen("test.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
team.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |