#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
// the most CHALISHKANCHIK
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
void solve(){
int n;
cin >> n;
set<vi> c;
for(int i = 0; i < n; i++){
vi b(3);
for(int &i:b)cin >> i;
c.insert(b);
}
vector<vi> a;
for(auto i:c)a.pb(i);
int ans = -1;
n = min(400ll, (int)a.size());
sort(rall(a));
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j)continue;
for(int k = 0; k < n; k++){
if(k == j || i == k)continue;
int mx1 = 0, mx2 = 0, mx3 = 0;
mx1 = max({a[i][0], a[j][0], a[k][0]});
mx2 = max({a[i][1], a[j][1], a[k][1]});
mx3 = max({a[i][2], a[j][2], a[k][2]});
bool ok1 = 0, ok2 = 0, ok3 = 0;
for(int h = 0; h < 3; h++){
if(a[i][h] > a[j][h] && a[i][h] > a[k][h])ok1 = 1;
if(a[j][h] > a[i][h] && a[j][h] > a[k][h])ok2 = 1;
if(a[k][h] > a[j][h] && a[k][h] > a[i][h])ok3 = 1;
}
if(ok1 && ok2 && ok3)ans = max(ans, mx1+mx2+mx3);
}for(int k = n-1; k >= max(0ll, n-400); k--){
if(k == j || i == k)continue;
int mx1 = 0, mx2 = 0, mx3 = 0;
mx1 = max({a[i][0], a[j][0], a[k][0]});
mx2 = max({a[i][1], a[j][1], a[k][1]});
mx3 = max({a[i][2], a[j][2], a[k][2]});
bool ok1 = 0, ok2 = 0, ok3 = 0;
for(int h = 0; h < 3; h++){
if(a[i][h] > a[j][h] && a[i][h] > a[k][h])ok1 = 1;
if(a[j][h] > a[i][h] && a[j][h] > a[k][h])ok2 = 1;
if(a[k][h] > a[j][h] && a[k][h] > a[i][h])ok3 = 1;
}
if(ok1 && ok2 && ok3)ans = max(ans, mx1+mx2+mx3);
}
}
for(int j = n-1; j >= max(0ll, n-350); j--){
if(i == j)continue;
for(int k = 0; k < min(350ll, n); k++){
if(k == j || i == k)continue;
int mx1 = 0, mx2 = 0, mx3 = 0;
mx1 = max({a[i][0], a[j][0], a[k][0]});
mx2 = max({a[i][1], a[j][1], a[k][1]});
mx3 = max({a[i][2], a[j][2], a[k][2]});
bool ok1 = 0, ok2 = 0, ok3 = 0;
for(int h = 0; h < 3; h++){
if(a[i][h] > a[j][h] && a[i][h] > a[k][h])ok1 = 1;
if(a[j][h] > a[i][h] && a[j][h] > a[k][h])ok2 = 1;
if(a[k][h] > a[j][h] && a[k][h] > a[i][h])ok3 = 1;
}
if(ok1 && ok2 && ok3)ans = max(ans, mx1+mx2+mx3);
}for(int k = n-1; k >= max(0ll, n-350); k--){
if(k == j || i == k)continue;
int mx1 = 0, mx2 = 0, mx3 = 0;
mx1 = max({a[i][0], a[j][0], a[k][0]});
mx2 = max({a[i][1], a[j][1], a[k][1]});
mx3 = max({a[i][2], a[j][2], a[k][2]});
bool ok1 = 0, ok2 = 0, ok3 = 0;
for(int h = 0; h < 3; h++){
if(a[i][h] > a[j][h] && a[i][h] > a[k][h])ok1 = 1;
if(a[j][h] > a[i][h] && a[j][h] > a[k][h])ok2 = 1;
if(a[k][h] > a[j][h] && a[k][h] > a[i][h])ok3 = 1;
}
if(ok1 && ok2 && ok3)ans = max(ans, mx1+mx2+mx3);
}
}
}
cout << ans << '\n';
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int test = 1;
//~ cin >> test;
while(test--){
solve();
}
}
Compilation message
team.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
91 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1006 ms |
508 KB |
Output is correct |
15 |
Correct |
387 ms |
344 KB |
Output is correct |
16 |
Correct |
636 ms |
484 KB |
Output is correct |
17 |
Correct |
765 ms |
596 KB |
Output is correct |
18 |
Correct |
805 ms |
484 KB |
Output is correct |
19 |
Correct |
947 ms |
596 KB |
Output is correct |
20 |
Correct |
383 ms |
468 KB |
Output is correct |
21 |
Correct |
368 ms |
348 KB |
Output is correct |
22 |
Correct |
574 ms |
596 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
681 ms |
500 KB |
Output is correct |
25 |
Correct |
666 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1006 ms |
508 KB |
Output is correct |
15 |
Correct |
387 ms |
344 KB |
Output is correct |
16 |
Correct |
636 ms |
484 KB |
Output is correct |
17 |
Correct |
765 ms |
596 KB |
Output is correct |
18 |
Correct |
805 ms |
484 KB |
Output is correct |
19 |
Correct |
947 ms |
596 KB |
Output is correct |
20 |
Correct |
383 ms |
468 KB |
Output is correct |
21 |
Correct |
368 ms |
348 KB |
Output is correct |
22 |
Correct |
574 ms |
596 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
681 ms |
500 KB |
Output is correct |
25 |
Correct |
666 ms |
488 KB |
Output is correct |
26 |
Execution timed out |
2066 ms |
1012 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
88 ms |
344 KB |
Output is correct |
12 |
Correct |
24 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
348 KB |
Output is correct |
14 |
Correct |
30 ms |
344 KB |
Output is correct |
15 |
Correct |
22 ms |
348 KB |
Output is correct |
16 |
Correct |
19 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
88 ms |
344 KB |
Output is correct |
12 |
Correct |
24 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
348 KB |
Output is correct |
14 |
Correct |
30 ms |
344 KB |
Output is correct |
15 |
Correct |
22 ms |
348 KB |
Output is correct |
16 |
Correct |
19 ms |
424 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
386 ms |
484 KB |
Output is correct |
21 |
Correct |
1774 ms |
700 KB |
Output is correct |
22 |
Incorrect |
1570 ms |
1620 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
88 ms |
344 KB |
Output is correct |
12 |
Correct |
24 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
348 KB |
Output is correct |
14 |
Correct |
30 ms |
344 KB |
Output is correct |
15 |
Correct |
22 ms |
348 KB |
Output is correct |
16 |
Correct |
19 ms |
424 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
386 ms |
484 KB |
Output is correct |
21 |
Correct |
1774 ms |
700 KB |
Output is correct |
22 |
Incorrect |
1570 ms |
1620 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
88 ms |
344 KB |
Output is correct |
12 |
Correct |
24 ms |
348 KB |
Output is correct |
13 |
Correct |
26 ms |
348 KB |
Output is correct |
14 |
Correct |
30 ms |
344 KB |
Output is correct |
15 |
Correct |
22 ms |
348 KB |
Output is correct |
16 |
Correct |
19 ms |
424 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
386 ms |
484 KB |
Output is correct |
21 |
Correct |
1774 ms |
700 KB |
Output is correct |
22 |
Incorrect |
1570 ms |
1620 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1006 ms |
508 KB |
Output is correct |
15 |
Correct |
387 ms |
344 KB |
Output is correct |
16 |
Correct |
636 ms |
484 KB |
Output is correct |
17 |
Correct |
765 ms |
596 KB |
Output is correct |
18 |
Correct |
805 ms |
484 KB |
Output is correct |
19 |
Correct |
947 ms |
596 KB |
Output is correct |
20 |
Correct |
383 ms |
468 KB |
Output is correct |
21 |
Correct |
368 ms |
348 KB |
Output is correct |
22 |
Correct |
574 ms |
596 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
681 ms |
500 KB |
Output is correct |
25 |
Correct |
666 ms |
488 KB |
Output is correct |
26 |
Execution timed out |
2066 ms |
1012 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |