landsky1234   2년 전

N = int(input())
arr = []cnt = 0for _ in range(N): st, ed = map(int, input().split()) if st == ed: cnt += 1 else: arr.append([st, ed])

if len(arr) > 0: sorted_arr = sorted(arr, key=lambda x:x[1]) start, end = sorted_arr[0][0], sorted_arr[0][1] cnt += 1 for i in range(1, len(sorted_arr)): if sorted_arr[i][0] == sorted_arr[i][1]: cnt += 1 continue if sorted_arr[i][1] < end: continue
if sorted_arr[i][0] >= end: start = sorted_arr[i][0] end = sorted_arr[i][1] cnt += 1
print(cnt)

eszaw12   2년 전

반례:

4

2 5

3 3

4 4

5 6

정답

3

출력

4

댓글을 작성하려면 로그인해야 합니다.