import heapq def check(D): global result possible_set = [] while rail_list: END,START = heapq.heappop(rail_list) if END-D <=START: heapq.heappush(possible_set,START) while possible_set and possible_set[0] < END-D: heapq.heappop(possible_set) result = max(result,len(possible_set)) N = int(input()) rail_list = [] for idx in range(N): A,B = map(int,input().split()) if A > B: A,B = B,A heapq.heappush(rail_list,(B,A)) d = int(input()) result = 0 check(d) print(result)
import heapq N = int(input()) rail_list = [] for idx in range(N): A,B = map(int,input().split()) if A > B: A,B = B,A rail_list.append((A,B)) rail_list.sort(key=lambda x : x[1]) in_rail = [] d = int(input()) result = 0 for start,end in rail_list: if end-d <= start: heapq.heappush(in_rail,start) while in_rail and end-d > in_rail[0]: heapq.heappop(in_rail) result = max(result,len(in_rail)) print(result)
'알고리즘 > 백준_복기_미완료' 카테고리의 다른 글
[BOJ/백준] 13460 구슬 탈출 2 (0) | 2021.05.05 |
---|---|
[BOJ/백준] 13458 시험감독 (0) | 2021.05.05 |
[BOJ/백준] 13302 리조트 (0) | 2021.05.05 |
[BOJ/백준] 13164 행복 유치원 (0) | 2021.05.05 |
[BOJ/백준] 2982 국왕의 방문 (0) | 2021.05.05 |