[백준] 2512번 예산, Python

이건회·2022년 1월 27일
0

백준

목록 보기
3/15
n=int(input())
requests=list(map(int,input().split()))
m=int(input())
requests.sort()

start=0
end=max(requests)
result=0

while(start<=end):
  total=0
  mid=(start+end)//2
  for i in requests:    
    if i>mid:
      total += mid
    else:
      total += i
  if total<=m:
    result=mid
    start=mid+1
  else:
    end=mid-1

print(result)

이진탐색을 떠올릴 수만 있으면 풀이법은 간단하다.

profile
하마드

0개의 댓글