#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
int main(){
AquA;
int n;
cin >> n;
vector<pair<int,pair<int,int> > > v(n);
int ans=-1,my=0,mz=0;
set<pair<int,int> > s;
for(int i=0;i<n;i++){
cin >> v[i].fs >> v[i].sc.fs >> v[i].sc.sc;
}
sort(v.begin(),v.end());
vector<pair<int,int> > g;
for(int i=0;i<n;i++){
auto h=v[i].sc;
if(my>h.fs && mz>h.sc){
ans=max(ans,v[i].fs+my+mz);
}
g.push_back(h);
if(i==n-1 || v[i].fs!=v[i+1].fs){
for(auto t:g){
if(s.empty()){
if(my<=t.fs && mz<=t.sc){
s.insert(t);
}
else{
my=max(my,t.fs);
mz=max(mz,t.sc);
}
continue;
}
auto y=s.lower_bound(t);
auto z=prev(y);
if((y==s.end() || ((*y).fs>=t.fs && (*y).sc>=t.sc)) && (y==s.begin() || ((*z).fs<=t.fs && (*z).sc<=t.sc))){
if(my<=t.fs && mz<=t.sc){
s.insert(t);
}
else{
my=max(my,t.fs);
mz=max(mz,t.sc);
}
}
else{
for(auto it=s.begin();it!=s.end();it=s.erase(it)){
if((*it).fs>=t.fs && (*it).sc>=t.sc){
break;
}
my=max(my,(*it).fs);
mz=max(mz,(*it).sc);
}
my=max(my,t.fs);
mz=max(mz,t.sc);
}
}
g.clear();
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |