제출 #782151

#제출 시각아이디문제언어결과실행 시간메모리
782151adaawfTeam Contest (JOI22_team)C++14
100 / 100
302 ms21836 KiB
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
pair<long long int, long long int> a[200005], b[200005], c[200005];
pair<long long int, pair<long long int, long long int>> p[200005];
int main() {
    int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i].first >> p[i].second.first >> p[i].second.second;
		a[i] = {p[i].first, i};
		b[i] = {p[i].second.first, i};
		c[i] = {p[i].second.second, i};
	}
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	sort(c + 1, c + n + 1);
	long long int x = n, y = n, z = n;
	set<long long int> s;
	while (1) {
		if (x == 0 || y == 0 || z == 0) {
            cout << -1;
            return 0;
		}
		if (s.find(a[x].second) != s.end()) {
            x--;
            continue;
        }
		if (s.find(b[y].second) != s.end()) {
            y--;
            continue;
        }
		if (s.find(c[z].second) != s.end()) {
            z--;
            continue;
        }
		if (a[x].second == b[y].second) {
		    s.insert(a[x].second);
            x--;
            continue;
        }
        if (a[x].second == c[z].second) {
            s.insert(a[x].second);
            x--;
            continue;
        }
		if (b[y].second == c[z].second) {
            s.insert(b[y].second);
            y--;
            continue;
        }
		if (p[a[x].second].second.first >= b[y].first) {
			s.insert(a[x].second);
			x--;
			continue;
		}
		if (p[a[x].second].second.second >= c[z].first) {
			s.insert(a[x].second);
			x--;
			continue;
		}
		if (p[b[y].second].first >= a[x].first) {
			s.insert(b[y].second);
			y--;
			continue;
		}
		if (p[b[y].second].second.second >= c[z].first) {
			s.insert(b[y].second);
			y--;
			continue;
		}
		if (p[c[z].second].first >= a[x].first) {
			s.insert(c[z].second);
			z--;
			continue;
		}
		if (p[c[z].second].second.first >= b[y].first) {
			s.insert(c[z].second);
			z--;
			continue;
		}
		cout << a[x].first + b[y].first + c[z].first;
		return 0;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...