2512 : 예산

서희찬·2022년 1월 27일
0

백준

목록 보기
101/105

문제

코드


n = int(input())
asset = list(map(int,input().split()))
chongAsset = int(input())

start,end = 0,max(asset)
result = []
while start<=end:
        mid =(start+end)//2 
        total =0 
        for x in asset:
            if x<mid:
                total+=x   
            else :                                 
                total+=mid 
        if total<=chongAsset:
            start = mid + 1 
        else : 
            end = mid - 1
            

print(end)

해설

total에 예산을 조건에 따라 더해나가며 이분탐색을 진행하는 알고리즘이다.

profile
Carnegie Mellon University Robotics Institute | Research Associate | Developing For Our Lives, 세상에 기여하는 삶을 살고자 개발하고 있습니다

0개의 댓글

관련 채용 정보