This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |