답안 #955311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955311 2024-03-30T05:54:56 Z LCJLY Team Contest (JOI22_team) C++14
100 / 100
110 ms 17076 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()&&!pq2.empty()){
			pii hold=pq.top();
			pii hold2=pq2.top();
			bool nxt=false;
			if(done[hold.second]){
				pq.pop();
				nxt=true;
			}
			if(done[hold2.second]){
				pq2.pop();
				nxt=true;
			}
			if(nxt) continue;
			if(arr[hold.second][2]>=hold2.first){
				pq.pop();
				done[hold.second]=true;
			}
			else if(arr[hold2.second][1]>=hold.first){
				pq2.pop();
				done[hold2.second]=true;
			}
			else break;
		}
		
		cur={-1,-1};
		cur2={-1,-1};
		
		
		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>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 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 736 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 2 ms 600 KB Output is correct
38 Correct 2 ms 600 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 552 KB Output is correct
3 Correct 1 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 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 66 ms 12208 KB Output is correct
12 Correct 45 ms 6340 KB Output is correct
13 Correct 48 ms 7360 KB Output is correct
14 Correct 59 ms 11888 KB Output is correct
15 Correct 64 ms 12220 KB Output is correct
16 Correct 62 ms 12468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 552 KB Output is correct
3 Correct 1 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 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 66 ms 12208 KB Output is correct
12 Correct 45 ms 6340 KB Output is correct
13 Correct 48 ms 7360 KB Output is correct
14 Correct 59 ms 11888 KB Output is correct
15 Correct 64 ms 12220 KB Output is correct
16 Correct 62 ms 12468 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 78 ms 12980 KB Output is correct
23 Correct 68 ms 11700 KB Output is correct
24 Correct 52 ms 6580 KB Output is correct
25 Correct 73 ms 12416 KB Output is correct
26 Correct 62 ms 11492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 552 KB Output is correct
3 Correct 1 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 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 66 ms 12208 KB Output is correct
12 Correct 45 ms 6340 KB Output is correct
13 Correct 48 ms 7360 KB Output is correct
14 Correct 59 ms 11888 KB Output is correct
15 Correct 64 ms 12220 KB Output is correct
16 Correct 62 ms 12468 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 78 ms 12980 KB Output is correct
23 Correct 68 ms 11700 KB Output is correct
24 Correct 52 ms 6580 KB Output is correct
25 Correct 73 ms 12416 KB Output is correct
26 Correct 62 ms 11492 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 85 ms 11328 KB Output is correct
35 Correct 81 ms 11956 KB Output is correct
36 Correct 88 ms 11956 KB Output is correct
37 Correct 97 ms 13488 KB Output is correct
38 Correct 66 ms 13492 KB Output is correct
39 Correct 39 ms 5820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 552 KB Output is correct
3 Correct 1 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 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 66 ms 12208 KB Output is correct
12 Correct 45 ms 6340 KB Output is correct
13 Correct 48 ms 7360 KB Output is correct
14 Correct 59 ms 11888 KB Output is correct
15 Correct 64 ms 12220 KB Output is correct
16 Correct 62 ms 12468 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 78 ms 12980 KB Output is correct
23 Correct 68 ms 11700 KB Output is correct
24 Correct 52 ms 6580 KB Output is correct
25 Correct 73 ms 12416 KB Output is correct
26 Correct 62 ms 11492 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 85 ms 11328 KB Output is correct
35 Correct 81 ms 11956 KB Output is correct
36 Correct 88 ms 11956 KB Output is correct
37 Correct 97 ms 13488 KB Output is correct
38 Correct 66 ms 13492 KB Output is correct
39 Correct 39 ms 5820 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 600 KB Output is correct
44 Correct 93 ms 13240 KB Output is correct
45 Correct 94 ms 15316 KB Output is correct
46 Correct 97 ms 14824 KB Output is correct
47 Correct 88 ms 14512 KB Output is correct
48 Correct 72 ms 15404 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 736 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 2 ms 600 KB Output is correct
38 Correct 2 ms 600 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 552 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 66 ms 12208 KB Output is correct
51 Correct 45 ms 6340 KB Output is correct
52 Correct 48 ms 7360 KB Output is correct
53 Correct 59 ms 11888 KB Output is correct
54 Correct 64 ms 12220 KB Output is correct
55 Correct 62 ms 12468 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 78 ms 12980 KB Output is correct
62 Correct 68 ms 11700 KB Output is correct
63 Correct 52 ms 6580 KB Output is correct
64 Correct 73 ms 12416 KB Output is correct
65 Correct 62 ms 11492 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 2 ms 604 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 344 KB Output is correct
73 Correct 85 ms 11328 KB Output is correct
74 Correct 81 ms 11956 KB Output is correct
75 Correct 88 ms 11956 KB Output is correct
76 Correct 97 ms 13488 KB Output is correct
77 Correct 66 ms 13492 KB Output is correct
78 Correct 39 ms 5820 KB Output is correct
79 Correct 2 ms 604 KB Output is correct
80 Correct 2 ms 604 KB Output is correct
81 Correct 2 ms 604 KB Output is correct
82 Correct 3 ms 600 KB Output is correct
83 Correct 93 ms 13240 KB Output is correct
84 Correct 94 ms 15316 KB Output is correct
85 Correct 97 ms 14824 KB Output is correct
86 Correct 88 ms 14512 KB Output is correct
87 Correct 72 ms 15404 KB Output is correct
88 Correct 88 ms 16720 KB Output is correct
89 Correct 96 ms 16844 KB Output is correct
90 Correct 86 ms 17076 KB Output is correct
91 Correct 94 ms 16456 KB Output is correct
92 Correct 110 ms 14432 KB Output is correct
93 Correct 90 ms 15344 KB Output is correct
94 Correct 91 ms 16052 KB Output is correct
95 Correct 77 ms 15828 KB Output is correct
96 Correct 87 ms 15648 KB Output is correct
97 Correct 73 ms 16048 KB Output is correct
98 Correct 68 ms 14012 KB Output is correct
99 Correct 82 ms 15024 KB Output is correct