티스토리 뷰
import sys
N, M = map(int, sys.stdin.readline().split())
# N: 나무의 수
# M: 집에 가져가려고 하는 나무 길이
data = list(map(int, sys.stdin.readline().split()))
left = 1
right = max(data)
while left <= right:
mid = (right + left) // 2
count = 0
for i in data:
if i >= mid:
count += i - mid
else:
count += 0
if count >= M:
left = mid + 1
else:
right = mid - 1
print(right)
Binary Search로 풀면 된다.
'Algorithm > noj.am' 카테고리의 다른 글
[Python] 백준 10816번 - 숫자카드 2 / try-except로 딕셔너리 초기화하기 (0) | 2021.01.21 |
---|---|
[Python] 백준 10825번 - 국영수 / 여러 조건 한번에 sort하기 (0) | 2021.01.21 |
[Python] 백준 1260번 - DFS와 BFS (0) | 2021.01.12 |
[Python] 백준 11651번 - 좌표 정렬하기 2 (0) | 2021.01.11 |
[Python] 백준 11650번 - 좌표 정렬하기 (0) | 2021.01.11 |