πŸ€–/λ°±μ€€

λ°±μ€€ 1931: νšŒμ˜μ‹€ λ°°μ • (Python)

sssbin 2021. 9. 27. 18:07

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

 

1931번: νšŒμ˜μ‹€ λ°°μ •

(1,4), (5,7), (8,11), (12,14) λ₯Ό μ΄μš©ν•  수 μžˆλ‹€.

www.acmicpc.net

 

n = int(input())
time = []

for i in range(n):
    start, end = map(int, input().split())
    time.append((end, start))

time.sort()
cnt = 0
end = 0

for i in range(n):
    if time[i][1] >= end:
        cnt += 1
        end = time[i][0]

print(cnt)

 

1. νšŒμ˜μ‹œκ°„μ„ λλ‚˜λŠ” μ‹œκ°„ 순 - μ‹œμž‘ μ‹œκ°„ 순으둜 μ •λ ¬ν•œ ν›„

2. 리슀트(μ‹œκ°„) λ‚΄μ—μ„œ μ°¨λ‘€λŒ€λ‘œ λ°˜λ³΅λ¬Έμ„ λŒλ©΄μ„œ μ‹œμž‘ μ‹œκ°„μ΄ λλ‚˜λŠ” μ‹œκ°„λ³΄λ‹€ κ°™κ±°λ‚˜ 크면 cnt + 1

 

λλ‚˜λŠ” μ‹œκ°„μœΌλ‘œ λ¨Όμ € μ •λ ¬ν•˜κΈ° μœ„ν•΄ 리슀트 내에 μ‹œκ°„μ„  end - start 순으둜 μ‚½μž…ν–ˆλ‹€!