From c9c076be0b870253cfb330a5c1f8cf71e6dba8a5 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sun, 10 Mar 2024 14:37:44 +0900 Subject: [PATCH] 2024-03-10 --- H0ngJu/README.md | 1 + ...\354\247\270 \355\201\260 \354\210\230.py" | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 "H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..2d4e7722 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -3,5 +3,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | --- diff --git "a/H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" "b/H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" new file mode 100644 index 00000000..5a22ef79 --- /dev/null +++ "b/H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" @@ -0,0 +1,19 @@ +import sys +import heapq + +line = int(sys.stdin.readline().strip()) + +heap = [] +heapq.heapify(heap) + +for i in range(line): + data = list(map(int, sys.stdin.readline().strip().split())) + for s in data: + if len(heap) < line: + heapq.heappush(heap, s) + else: + if s > heap[0]: + heapq.heappop(heap) + heapq.heappush(heap, s) + +print(heap[0]) \ No newline at end of file