#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=4010;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
if(n<=300){
vector<int> a(n),b(n),c(n);
for(int i=0;i<n;i++){
cin>>a[i]>>b[i]>>c[i];
}
int ans=-1;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
if(i==j||j==k||i==k){
continue;
}
if(a[i]<=a[j]||a[i]<=a[k]||b[j]<=b[i]||b[j]<=b[k]||c[k]<=c[i]||c[k]<=c[j]){
continue;
}
ans=max(ans,a[i]+b[j]+c[k]);
}
}
}
cout<<ans<<endl;
return 0;
}
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,-INF),rec1(N+2,-INF);
int ans=-INF;
for(int i=1;i<=N;i++){
for(auto p:v[i]){
for(int j=p.first+1;j<=N+1;j++){
if(rec1[j]>p.second)ans=max(ans,i+j+rec1[j]);
}
}
for(auto p:v[i]){
rec[p.first+1]=max(rec[p.first+1],p.second);
}
for(int j=1;j<=N;j++){
rec[j]=max(rec[j],rec[j-1]);
}
for(auto p:v[i]){
if(rec[p.first]>p.second){
rec1[p.first]=max(rec[p.first],rec1[p.first]);
}
}
for(int j=N-1;j>=0;j--){
rec1[j]=max(rec1[j],rec1[j+1]);
}
}
if(ans<0){
cout<<-1<<endl;
}
else{
cout<<ans<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
75 ms |
212 KB |
Output is correct |
15 |
Correct |
30 ms |
212 KB |
Output is correct |
16 |
Correct |
49 ms |
212 KB |
Output is correct |
17 |
Correct |
60 ms |
312 KB |
Output is correct |
18 |
Correct |
57 ms |
212 KB |
Output is correct |
19 |
Correct |
71 ms |
312 KB |
Output is correct |
20 |
Correct |
58 ms |
344 KB |
Output is correct |
21 |
Correct |
48 ms |
320 KB |
Output is correct |
22 |
Correct |
47 ms |
212 KB |
Output is correct |
23 |
Correct |
42 ms |
212 KB |
Output is correct |
24 |
Correct |
46 ms |
308 KB |
Output is correct |
25 |
Correct |
42 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
75 ms |
212 KB |
Output is correct |
15 |
Correct |
30 ms |
212 KB |
Output is correct |
16 |
Correct |
49 ms |
212 KB |
Output is correct |
17 |
Correct |
60 ms |
312 KB |
Output is correct |
18 |
Correct |
57 ms |
212 KB |
Output is correct |
19 |
Correct |
71 ms |
312 KB |
Output is correct |
20 |
Correct |
58 ms |
344 KB |
Output is correct |
21 |
Correct |
48 ms |
320 KB |
Output is correct |
22 |
Correct |
47 ms |
212 KB |
Output is correct |
23 |
Correct |
42 ms |
212 KB |
Output is correct |
24 |
Correct |
46 ms |
308 KB |
Output is correct |
25 |
Correct |
42 ms |
332 KB |
Output is correct |
26 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
546 ms |
6428 KB |
Output is correct |
12 |
Correct |
401 ms |
4812 KB |
Output is correct |
13 |
Correct |
489 ms |
5560 KB |
Output is correct |
14 |
Correct |
524 ms |
7464 KB |
Output is correct |
15 |
Correct |
556 ms |
7320 KB |
Output is correct |
16 |
Correct |
545 ms |
8156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
546 ms |
6428 KB |
Output is correct |
12 |
Correct |
401 ms |
4812 KB |
Output is correct |
13 |
Correct |
489 ms |
5560 KB |
Output is correct |
14 |
Correct |
524 ms |
7464 KB |
Output is correct |
15 |
Correct |
556 ms |
7320 KB |
Output is correct |
16 |
Correct |
545 ms |
8156 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
57 ms |
308 KB |
Output is correct |
21 |
Correct |
112 ms |
576 KB |
Output is correct |
22 |
Correct |
552 ms |
6780 KB |
Output is correct |
23 |
Correct |
551 ms |
6504 KB |
Output is correct |
24 |
Correct |
419 ms |
5212 KB |
Output is correct |
25 |
Correct |
598 ms |
7164 KB |
Output is correct |
26 |
Correct |
562 ms |
6620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
546 ms |
6428 KB |
Output is correct |
12 |
Correct |
401 ms |
4812 KB |
Output is correct |
13 |
Correct |
489 ms |
5560 KB |
Output is correct |
14 |
Correct |
524 ms |
7464 KB |
Output is correct |
15 |
Correct |
556 ms |
7320 KB |
Output is correct |
16 |
Correct |
545 ms |
8156 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
57 ms |
308 KB |
Output is correct |
21 |
Correct |
112 ms |
576 KB |
Output is correct |
22 |
Correct |
552 ms |
6780 KB |
Output is correct |
23 |
Correct |
551 ms |
6504 KB |
Output is correct |
24 |
Correct |
419 ms |
5212 KB |
Output is correct |
25 |
Correct |
598 ms |
7164 KB |
Output is correct |
26 |
Correct |
562 ms |
6620 KB |
Output is correct |
27 |
Correct |
62 ms |
332 KB |
Output is correct |
28 |
Correct |
76 ms |
308 KB |
Output is correct |
29 |
Correct |
45 ms |
304 KB |
Output is correct |
30 |
Correct |
52 ms |
312 KB |
Output is correct |
31 |
Correct |
123 ms |
596 KB |
Output is correct |
32 |
Correct |
109 ms |
496 KB |
Output is correct |
33 |
Correct |
107 ms |
504 KB |
Output is correct |
34 |
Correct |
528 ms |
6860 KB |
Output is correct |
35 |
Correct |
544 ms |
7452 KB |
Output is correct |
36 |
Correct |
537 ms |
7516 KB |
Output is correct |
37 |
Correct |
537 ms |
7280 KB |
Output is correct |
38 |
Correct |
521 ms |
6612 KB |
Output is correct |
39 |
Correct |
377 ms |
4680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
546 ms |
6428 KB |
Output is correct |
12 |
Correct |
401 ms |
4812 KB |
Output is correct |
13 |
Correct |
489 ms |
5560 KB |
Output is correct |
14 |
Correct |
524 ms |
7464 KB |
Output is correct |
15 |
Correct |
556 ms |
7320 KB |
Output is correct |
16 |
Correct |
545 ms |
8156 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
57 ms |
308 KB |
Output is correct |
21 |
Correct |
112 ms |
576 KB |
Output is correct |
22 |
Correct |
552 ms |
6780 KB |
Output is correct |
23 |
Correct |
551 ms |
6504 KB |
Output is correct |
24 |
Correct |
419 ms |
5212 KB |
Output is correct |
25 |
Correct |
598 ms |
7164 KB |
Output is correct |
26 |
Correct |
562 ms |
6620 KB |
Output is correct |
27 |
Correct |
62 ms |
332 KB |
Output is correct |
28 |
Correct |
76 ms |
308 KB |
Output is correct |
29 |
Correct |
45 ms |
304 KB |
Output is correct |
30 |
Correct |
52 ms |
312 KB |
Output is correct |
31 |
Correct |
123 ms |
596 KB |
Output is correct |
32 |
Correct |
109 ms |
496 KB |
Output is correct |
33 |
Correct |
107 ms |
504 KB |
Output is correct |
34 |
Correct |
528 ms |
6860 KB |
Output is correct |
35 |
Correct |
544 ms |
7452 KB |
Output is correct |
36 |
Correct |
537 ms |
7516 KB |
Output is correct |
37 |
Correct |
537 ms |
7280 KB |
Output is correct |
38 |
Correct |
521 ms |
6612 KB |
Output is correct |
39 |
Correct |
377 ms |
4680 KB |
Output is correct |
40 |
Incorrect |
116 ms |
596 KB |
Output isn't correct |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
75 ms |
212 KB |
Output is correct |
15 |
Correct |
30 ms |
212 KB |
Output is correct |
16 |
Correct |
49 ms |
212 KB |
Output is correct |
17 |
Correct |
60 ms |
312 KB |
Output is correct |
18 |
Correct |
57 ms |
212 KB |
Output is correct |
19 |
Correct |
71 ms |
312 KB |
Output is correct |
20 |
Correct |
58 ms |
344 KB |
Output is correct |
21 |
Correct |
48 ms |
320 KB |
Output is correct |
22 |
Correct |
47 ms |
212 KB |
Output is correct |
23 |
Correct |
42 ms |
212 KB |
Output is correct |
24 |
Correct |
46 ms |
308 KB |
Output is correct |
25 |
Correct |
42 ms |
332 KB |
Output is correct |
26 |
Runtime error |
1 ms |
724 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |