Skip to content

Commit

Permalink
Merge pull request #161 from AlgoLeadMe/11-ljedd2_
Browse files Browse the repository at this point in the history
11 ljedd2
  • Loading branch information
LJEDD2 authored Nov 22, 2024
2 parents ba06c01 + 79029cf commit a7069d8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion LJEDD2/2024-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
| 6차시 | 2024.08.03 | 완전탐색 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/87946">피로도</a> | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/141) |
| 7차시 | 2024.09.01 | 위상정렬 | <a href="https://www.acmicpc.net/problem/2252">줄 세우기</a> | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/152) |
| 8차시 | 2024.09.04 | 위상정렬 | <a href="https://www.acmicpc.net/problem/1766">문제집</a> | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/154) |
| 9차시 | 2024.09.07 | 스택 | <a href="https://www.acmicpc.net/problem/2176">원숭이 매달기</a> | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) |
| 9차시 | 2024.09.07 | 스택 | <a href="https://www.acmicpc.net/problem/2176">원숭이 매달기</a> | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) |
| 10차시 | 2024.09.11 | 우선순위 큐 | <a href="https://www.acmicpc.net/problem/1715">카드 정렬하기</a> | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) |
17 changes: 17 additions & 0 deletions LJEDD2/2024-2/우선순위큐/N번째 큰 수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys, heapq
input = sys.stdin.readline

n = int(input())
heap = []

for _ in range(n):
for number in map(int, input().split()):

if len(heap) < n: # 비교 대상이 모자랄 경우
heapq.heappush(heap, number) #그대로 추가

else:
if number > heap[0]: # 제일 작은것보다 크면
heapq.heapreplace(heap, number) #작은거 빼고 큰거 넣어줌

print(heap[0]) # 맨앞에 있는게 N번째로 큰놈
17 changes: 17 additions & 0 deletions LJEDD2/2024-2/우선순위큐/카드 합체 놀이.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import heapq
n, m = map(int,input().split())

#힙 구조로 변환
numbers = list(map(int,input().split()))
heapq.heapify(numbers)

for _ in range(m):

x = heapq.heappop(numbers)
y = heapq.heappop(numbers)

# x와 y 둘 다 값 교체
heapq.heappush(numbers, x+y)
heapq.heappush(numbers, x+y)

print(sum(numbers))

0 comments on commit a7069d8

Please sign in to comment.