이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using matr = array <int, 3>;
matr a[4001];
matr b[4001];
int n;
int mx = -1;
void solve () {
	sort(b + 1, b + n + 1);
	int ptr = 0;
	for (int i = 1; i <= n; i++) { //i is larger than anything <= ptr in a
		while (ptr + 1 < i && b[ptr + 1][0] < b[i][0]) ptr++;
		if (ptr != 0) sort(b + 1, b + ptr + 1, [] (matr &x, matr &y) {
			return x[1] < y[1];
		});
		int mx2 = 0, ptr2 = 0;
		for (int j = 1; j <= ptr; j++) {
			if (b[j][1] <= b[i][1]) continue;
			while (ptr2 + 1 < j && b[ptr2 + 1][1] < b[j][1]) {
				ptr2++; mx2 = max(mx2, b[ptr2][2]);
			}
			if (mx2 > max(b[j][2], b[i][2])) {
				mx = max(mx, mx2 + b[j][1] + b[i][0]);
			}
		}
	}	
}
int main () {
	cin >> n;
	for (int i = 1; i <= n; i++) for (int j = 0; j < 3; j++) cin >> a[i][j], b[i][j] = a[i][j];
	solve();
	/*vector <int> u = {0, 1, 2};
	do {
		for (int i = 1; i <= n; i++) {
			matr v;
			v[0] = a[i][u[0]];
			v[1] = a[i][u[1]];
			v[2] = a[i][u[2]];
			b[i] = v;
		}
		solve();
	} while (next_permutation(u.begin(), u.end()));*/
	cout << mx << '\n';
}
| # | 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... |