제출 #697562

#제출 시각아이디문제언어결과실행 시간메모리
697562emptypringlescanTeam Contest (JOI22_team)C++17
100 / 100
97 ms11812 KiB
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<pair<int,int>,pair<int,int> > a,pair<pair<int,int>,pair<int,int> > b){
	return a.first.second>b.first.second;
}
bool cmp2(pair<pair<int,int>,pair<int,int> > a,pair<pair<int,int>,pair<int,int> > b){
	return a.second.first>b.second.first;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	pair<pair<int,int>,pair<int,int> > tp[n],tp2[n],tp3[n];
	for(int i=0; i<n; i++){
		int a,b,c;
		cin >> a >> b >> c;
		tp[i]=tp2[i]=tp3[i]={{a,b},{c,i}};
	}
	sort(tp,tp+n,greater<pair<pair<int,int>,pair<int,int> > >());
	sort(tp2,tp2+n,cmp);
	sort(tp3,tp3+n,cmp2);
	int c1=0,c2=0,c3=0,del[n];
	memset(del,0,sizeof(del));
	while(true){
		
		while(c1<n&&del[tp[c1].second.second]){
			c1++;
		}
		while(c2<n&&del[tp2[c2].second.second]){
			c2++;
		}
		while(c3<n&&del[tp3[c3].second.second]){
			c3++;
		}
		if(c1>=n||c2>=n||c3>=n) break;/*
		cout << c1 << ' ' << c2 << ' ' << c3 << '\n';
		cout << tp[c1].first.first << ' ' << tp[c1].first.second << ' ' << tp[c1].second.first << "   ";
		cout << tp2[c2].first.first << ' ' << tp2[c2].first.second << ' ' << tp2[c2].second.first << "   ";
		cout << tp3[c3].first.first << ' ' << tp3[c3].first.second << ' ' << tp3[c3].second.first << "   ";
		cout << "\n";*/
		if(tp2[c2].first.first>=tp[c1].first.first){
			del[tp2[c2].second.second]=1;
			c2++;
			continue;
		}
		if(tp3[c3].first.first>=tp[c1].first.first){
			del[tp3[c3].second.second]=1;
			c3++;
			continue;
		}
		if(tp[c1].first.second>=tp2[c2].first.second){
			del[tp[c1].second.second]=1;
			c1++;
			continue;
		}
		if(tp3[c3].first.second>=tp2[c2].first.second){
			del[tp3[c3].second.second]=1;
			c3++;
			continue;
		}
		if(tp2[c2].second.first>=tp3[c3].second.first){
			del[tp2[c2].second.second]=1;
			c2++;
			continue;
		}
		if(tp[c1].second.first>=tp3[c3].second.first){
			del[tp[c1].second.second]=1;
			c1++;
			continue;
		}
		cout << tp[c1].first.first+tp2[c2].first.second+tp3[c3].second.first;
		return 0;
	}
	cout << -1;
}

#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...