[백준] 2437 - 저울 (그리디)

김영민·2024년 8월 21일
0

코딩테스트

목록 보기
21/32


코드

K = int(input())

weights = list(map(int, input().split()))



result = 1
weights.sort()


for w in weights:
    if result < w:
        break
    result += w


print(result)

풀이

  • 우선 weight를 정렬.
  • 초기값은 1로 설정.
  • [이전까지의 합+1]이 다음 weight보다 커야 가능함.
  • https://aerocode.net/392 해당 블로그가 가장 이해하기 쉬웠음.

0개의 댓글