#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define rz resize
#define pb emplace_back
int INF=1e18;
int mod=1e9+7;
int N=4000;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<int> a(n),b(n),c(n);
vector<vector<pii>> v(N+1);
for(int i=0;i<n;i++){
cin>>a[i]>>b[i]>>c[i];
v[a[i]].push_back({b[i],c[i]});
}
vector<int> rec(N+2),rec1(N+2);
int ans=-1;
for(int i=1;i<=N;i++){
for(auto p:v[i]){
if(p.second<rec[p.first+1]){
ans=max(ans,i+rec[p.first+1]+p.first);
}
}
for(auto p:v[i]){
rec[p.first]=max(rec[p.first],p.second);
}
for(int j=2;j<=N;j++){
rec[j]=max(rec[j],rec[j-1]);
}
for(auto p:v[i]){
if(rec[p.first-1]>p.second){
rec1[p.first]=max(rec[p.first-1],rec1[p.first]);
}
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
468 KB |
Output is correct |
2 |
Correct |
55 ms |
468 KB |
Output is correct |
3 |
Correct |
55 ms |
468 KB |
Output is correct |
4 |
Incorrect |
53 ms |
468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
468 KB |
Output is correct |
2 |
Correct |
55 ms |
468 KB |
Output is correct |
3 |
Correct |
55 ms |
468 KB |
Output is correct |
4 |
Incorrect |
53 ms |
468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
448 KB |
Output is correct |
2 |
Correct |
53 ms |
468 KB |
Output is correct |
3 |
Correct |
57 ms |
340 KB |
Output is correct |
4 |
Incorrect |
54 ms |
448 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
448 KB |
Output is correct |
2 |
Correct |
53 ms |
468 KB |
Output is correct |
3 |
Correct |
57 ms |
340 KB |
Output is correct |
4 |
Incorrect |
54 ms |
448 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
448 KB |
Output is correct |
2 |
Correct |
53 ms |
468 KB |
Output is correct |
3 |
Correct |
57 ms |
340 KB |
Output is correct |
4 |
Incorrect |
54 ms |
448 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
448 KB |
Output is correct |
2 |
Correct |
53 ms |
468 KB |
Output is correct |
3 |
Correct |
57 ms |
340 KB |
Output is correct |
4 |
Incorrect |
54 ms |
448 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
468 KB |
Output is correct |
2 |
Correct |
55 ms |
468 KB |
Output is correct |
3 |
Correct |
55 ms |
468 KB |
Output is correct |
4 |
Incorrect |
53 ms |
468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |