-
2805. 나무 자르기코테 준비/이진탐색 2022. 12. 8. 20:23
시간 초과 때문에 10번은 넘게 시도했던 문제였다....
import sys n,m=map(int,sys.stdin.readline().split()) h=list(map(int,sys.stdin.readline().split())) start=1 end=max(h) while start<=end: #newh==m이 될때까지 mid=(start+end)//2 #이진탐색 newh=0 for i in h: if i>mid: newh+=(i-mid) if newh>m: #원하는 길이를 넘으면 break break if newh>=m: start=mid+1 elif newh<m: end=mid-1 print(end) #start로 해도 상관 없음
'코테 준비 > 이진탐색' 카테고리의 다른 글
[백준] 2470. 두용액 (투 포인터) (0) 2023.02.07 1654. 랜선 자르기 (Python) (0) 2022.12.08