[백준] 2512번 : 예산 - Python(파이썬)

강재원·2022년 11월 2일
0

[코딩테스트] Python

목록 보기
170/200



https://www.acmicpc.net/problem/2512

n=int(input())
arr=[0]*n
st=list(map(int,input().split()))
for i in range(n):
    arr[i]=st[i]
max=int(input())
arr.sort()

left=0
right=arr[n-1]

while left<=right:
    mid=(left+right)//2
    now=0
    for i in range(n):
        if mid>=arr[i]: now+=arr[i]
        else: now+=mid
    if now>max: right=mid-1
    else: left=mid+1

print(right)
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글