Python(백준)/정렬
[백준 파이썬 25305번]커트라인★SORTED()★우선순위 큐로 풀어보기★VER2.0
goAhEAd_29
2023. 4. 9. 20:19
728x90
반응형
VERSION 2.0
import heapq
import sys
N ,k = list(map(int, sys.stdin.readline().split()))
x = list(map(int,sys.stdin.readline().split()))
heapq.heapify(x)
# print(x)
for i in range(len(x)-k):
heapq.heappop(x)
print(heapq.heappop(x))
==> heapq.heapify(x) ==> 리스트 x를 heap화 한다!!!
==> heapq.heappop() 할시 ==> 작은값을 먼저 뽑아낸다!!!!!
VERSION 1.0
import sys
N = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
b = sorted(A , reverse = True)
print(b[N[1]-1])
별게 없다. 동점자여도 그냥 2번째꺼 뽑아내면 된다.
728x90
반응형