Skip to content

Commit

Permalink
[코딩테스트책] 7-2. 떡볶이 떡 만들기 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
heerucan committed Feb 27, 2022
1 parent 073140e commit 3415c8c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CodingTest/CH7 이진탐색/떡볶이떡만들기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 4 6
# 19 15 10 17

import sys

n, m = list(map(int, input().split())) # 떡의 개수, 원하는 떡 길이
# array = sys.stdin.readline().rstrip()
array = list(map(int, input().split())) # 떡 개별 높이
array.sort() # 이진탐색을 위해 정렬


def binary_search(array, start, end):
result = 0
while m != result:
mid = (start + end) // 2
for i in range(len(array)):
if array[mid] < array[i]:
result += (array[i] - array[mid])
else:
result += 0
print(array[mid])

binary_search(array, 0, n-1)

0 comments on commit 3415c8c

Please sign in to comment.