답안 #955305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955305 2024-03-30T05:46:31 Z LCJLY Team Contest (JOI22_team) C++14
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

void solve(){
	int n;
	cin >> n;
	array<int,3> arr[n];
	for(int x=0;x<n;x++){
		cin >> arr[x][0] >> arr[x][1] >> arr[x][2];
	}
	
	sort(arr,arr+n);
	reverse(arr,arr+n);
	int best=-1;
	priority_queue<pii>pq,pq2;
	bool done[n+5];
	memset(done,0,sizeof(done));
	for(int x=0;x<n;x++){
		pq.push({arr[x][1],x});
		pq2.push({arr[x][2],x});
	}
	
	//for(int x=0;x<n;x++){
		//cout << arr[x][0] << " " << arr[x][1] << " " << arr[x][2] << endl;
	//}
	
	int ptr=0;
	for(int x=0;x<n;x++){
		while(ptr<n&&arr[ptr][0]>=arr[x][0]){
			done[ptr]=true;
			ptr++;
		}
		pii cur={-1,-1};
		pii cur2={-1,-1};
		while(!pq.empty()){
			cur=pq.top();
			if(!done[cur.second]&&!pq2.empty()&&arr[cur.second][2]==pq2.top().first){
				done[cur.second]=true;
			}
			else if(!done[cur.second]){
				break;
			}
			pq.pop();
			cur={-1,-1};
		}
		while(!pq2.empty()){
			cur2=pq2.top();
			if(!done[cur2.second]&&!pq.empty()&&arr[cur2.second][1]==pq.top().first){
				done[cur2.second]=true;
			}
			else if(!done[cur2.second]){
				break;
			}
			pq2.pop();
			cur2={-1,-1};
		}
		cur={-1,-1};
		cur2={-1,-1};
		while(!pq.empty()&&done[pq.top().second]) pq.pop();
		while(!pq2.empty()&&done[pq2.top().second]) pq2.pop();
		
		if(!pq.empty()) cur=pq.top();
		if(!pq2.empty()) cur2=pq2.top();
		
		//show2(cur.first,cur.first,cur2.first,cur2.first);
		//show2(cur.second,cur.second,cur2.second,cur2.second);
		if(cur.first!=-1)assert(cur.second!=cur2.second);
		if(cur.first!=-1)assert(x!=cur.second);
		if(cur.first>arr[x][1]&&cur2.first>arr[x][2]){
			best=max(best,arr[x][0]+cur.first+cur2.first);
		}	
		//show4(done,done);
	}
	cout << best;
}	
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
6 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
6 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
6 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
6 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -