-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## 백준 2963 | ||
https://www.acmicpc.net/problem/2963 | ||
|
||
> 배열 A가 주어졌을 때, N번째 큰 값을 출력하는 프로그램을 작성하시오. | ||
|
||
### 소스코드 | ||
```py | ||
import heapq | ||
from typing import List | ||
|
||
|
||
T = int(input()) | ||
|
||
def solve(A: List[int]): | ||
hq = list(map(lambda a: -a, A)) | ||
heapq.heapify(hq) | ||
|
||
for _ in range(2): | ||
heapq.heappop(hq) | ||
|
||
return -heapq.heappop(hq) | ||
|
||
|
||
for _ in range(T): | ||
A = list(map(int, input().split())) | ||
|
||
print(solve(A)) | ||
|
||
|
||
``` | ||
|
||
### 해설 | ||
입력받은 배열을 heapify한 다음 heappop을 3번 수행한 결과값을 리턴한다. |