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;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
vector<int> Y;
vector<int> Z;
vector<int> X;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
X.resize(n);
Y.resize(n);
Z.resize(n);
vector<int> w(n);
for(int i=0;i<n;i++) cin>>X[i]>>Y[i]>>Z[i];
for(int i=0;i<n;i++) {w[i]=i;}
sort(w.begin(),w.end(),[&](const int a,const int b){return Y[a]<Y[b];});
int ans = -1;
int prevy = 1e9;
for(int i=0;i<n;i++){
int maxn = -1e9;
vector<int> tadd;
for(int j=0;j<n;j++){
if(X[w[j]]>=X[i]) continue;
if(Y[w[j]]>prevy){
while(tadd.size()){
maxn = max(maxn,Z[tadd.back()]);
tadd.pop_back();
}
}
prevy = Y[w[j]];
tadd.push_back(w[j]);
if(Y[w[j]]>Y[i]){
if(maxn>Z[i] && maxn>Z[w[j]]){
// cout<<i<<" "<<w[j]<<" "<<maxn<<"\n";
ans = max(ans,maxn+Y[w[j]]+X[i]);
}
}
}
}
cout<<ans<<"\n";
return 0;
}
# | 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... |