Submission #711964

#TimeUsernameProblemLanguageResultExecution timeMemory
711964aryan12Team Contest (JOI22_team)C++17
100 / 100
138 ms17336 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() 
{
	int n;
	cin >> n;
	vector<array<int, 2> > a(n), b(n), c(n);
	vector<array<int, 3> > lmao;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i][0] >> b[i][0] >> c[i][0];
		a[i][1] = b[i][1] = c[i][1] = i;
		lmao.push_back({a[i][0], b[i][0], c[i][0]});
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	int x = n - 1, y = n - 1, z = n - 1;
	while(x != -1 && y != -1 && z != -1)
	{
		int X = a[x][1], Y = b[y][1], Z = c[z][1];
		if(lmao[X][1] >= lmao[Y][1] || lmao[X][2] >= lmao[Z][2])
		{
			x--;
			continue;
		}
		if(lmao[Y][0] >= lmao[X][0] || lmao[Y][2] >= lmao[Z][2])
		{
			y--;
			continue;
		}
		if(lmao[Z][0] >= lmao[X][0] || lmao[Z][1] >= lmao[Y][1])
		{
			z--;
			continue;
		}
		cout << a[x][0] + b[y][0] + c[z][0] << "\n";
		return;
	}
	cout << "-1\n";
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	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...