๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์•Œ๊ณ ๋ฆฌ์ฆ˜ ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€

[BAEKJOON] 1946 | ์‹ ์ž… ์‚ฌ์›

by flowing1ife 2024. 12. 19.

๐Ÿ”Ž 1946 | ์‹œ๋ฆฌ์–ผ ๋ฒˆํ˜ธ

https://www.acmicpc.net/problem/1946


๐Ÿ’ก Solution

  1. ๋จผ์ € ์„œ๋ฅ˜ ์„ฑ์ ๊ณผ ๋ฉด์ ‘ ์„ฑ์ ์„ ๋ชจ๋‘ ์ž…๋ ฅ ๋ฐ›์•„ listํ™”ํ•œ๋‹ค.
  2. ์„œ๋ฅ˜ ์„ฑ์ ์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.
  3. ๋ณธ์ธ๋ณด๋‹ค ์„œ๋ฅ˜ ์„ฑ์ ์ด ์ข‹์€ ์‚ฌ๋žŒ๋“ค ์ค‘ ๊ฐ€์žฅ ์ข‹์€ ๋ฉด์ ‘ ์„ฑ์ ๋ณด๋‹ค ๋ฉด์ ‘ ์„ฑ์ ์ด ์ข‹์œผ๋ฉด ํ•ฉ๊ฒฉ์ด๋‹ค.
  4. ์ด ๋•Œ, ์„œ๋ฅ˜ ์„ฑ์ ์ด 1๋“ฑ์ธ ์‚ฌ๋žŒ์€ ์ ˆ๋Œ€ ๋‹ค๋ฅธ ์ง€์›์ž๋ณด๋‹ค ๋ชจ๋‘ ์„ฑ์ ์ด ๋–จ์–ด์งˆ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ๋ฌด์กฐ๊ฑด ์„ ๋ฐœ์ด๋‹ค.

import sys
input = sys.stdin.readline

def find_passed_count(n) :
    count = 1
    candidates = []
    for i in range(n) :
        document_score, interview_score = map(int, input().split())
        candidates.append((document_score, interview_score))
        
    candidates.sort(key = lambda x: (x[0]))
    
    threshold = candidates[0][1]
    for i in range(1, n) :
        if threshold > candidates[i][1] :
            count += 1
            threshold = candidates[i][1]
        
            
    return count

t = int(input().rstrip())

while t :
    n = int(input().rstrip())
    print(find_passed_count(n))
    t -= 1

๐Ÿ“Œ  Note

์ฒ˜์Œ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ด์ค‘ for๋ฌธ์„ ์‚ฌ์šฉํ–ˆ๋”๋‹ˆ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ O(N^2)์ด ๋‚˜์™€์„œ ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋–ด๋‹ค.
์›ฌ๋งŒํ•˜๋ฉด ์ด์ค‘ for๋ฌธ์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๊ฒƒ !

 

import sys
input = sys.stdin.readline

def find_passed_count(n) :
    count = n
    candidates = []
    for i in range(n) :
        document_score, interview_score = map(int, input().split())
        candidates.append((document_score, interview_score))
        
    candidates.sort(key = lambda x: (x[0]))
    
    for i in range(n) :
        for j in range(i) :
            if candidates[i][1] > candidates[j][1] :
                count -= 1
                break
            
    return count

t = int(input().rstrip())

while t :
    n = int(input().rstrip())
    print(find_passed_count(n))
    t -= 1โ€‹