File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
weekly/week4/BOJ_1946_신입사원 Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < algorithm>
3+ #include < vector>
4+
5+ using namespace std ;
6+
7+ int main () {
8+ int T;
9+ cin >> T;
10+ while (T--) {
11+ int n;
12+ cin >> n;
13+
14+ vector<pair<int , int >> v;
15+ for (int i = 0 ; i < n; i++) {
16+ int a, b;
17+ cin >> a >> b;
18+ v.push_back ({ a,b });
19+ }
20+
21+ sort (v.begin (), v.end ());
22+
23+ int cnt = 0 ; // 탈락한 애들 수
24+
25+ // 비교 원소 조건
26+ // 이전보다 first가 클 것 (항상 만족)
27+ // 이전보다 second가 작을 것
28+ int cmpA = v[0 ].first ;
29+ int cmpB = v[0 ].second ;
30+ for (int i = 1 ; i < v.size (); i++) {
31+ int curA = v[i].first ;
32+ int curB = v[i].second ;
33+
34+ if (curA > cmpA && curB > cmpB) {
35+ cnt++;
36+ }
37+ // 비교 원소 업데이트
38+ else {
39+ if (curB < cmpB) {
40+ cmpA = curA;
41+ cmpB = curB;
42+ }
43+ }
44+ }
45+
46+ cout << n - cnt << " \n " ;
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments