-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from AlgoLeadMe/11-ljedd2_
11 ljedd2
- Loading branch information
Showing
3 changed files
with
36 additions
and
1 deletion.
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
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,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번째로 큰놈 |
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,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)) |