import heapq, sys
input = sys.stdin.readline
heap = []
num = int(input())
for _ in range(num) :
array = list(map(int,input().split()))
if heap :
for a in array :
if a > heap[0] :
heapq.heappop(heap)
heapq.heappush(heap, a)
else :
for a in array :
heapq.heappush(heap, a)
print(heap[0])
힙을 이용해 해결했다.
모든 수를 다 넣고 해결하기에는 시간 복잡도가 매우 커진다.
파이썬은 최소 힙을 이용하기 때문에 힙의 크기를 N으로 제한하고, 0번째에 있는 수를 출력하게 되면 N번째 큰 수가 된다.
'프로그램 > 코딩테스트' 카테고리의 다른 글
백준 10448 유레카 이론 (0) | 2022.06.13 |
---|---|
백준 3040 백설 공주와 일곱 난쟁이 (0) | 2022.06.13 |
백준 1935 후위 표기식2 (0) | 2022.06.13 |
백준 5397 키로거 (0) | 2022.06.13 |
백준 7785 회사에 있는 사람 (0) | 2022.06.13 |
댓글