https://www.acmicpc.net/problem/2785
n = int(input())
chain = list(map(int, input().split()))
chain.sort()
cnt = 1
x = 0
while True:
chain[x] -= 1
cnt += 1
if chain[x] == 0:
x += 1
if cnt + x >= n:
break
print(cnt - 1)
chain
리스트를 오름차순 정렬cnt
와 x
를 초기화[cnt를 1로 초기화한 이유는 고리하나당 2개를 연결할 수 있기 때문]
[x]
번째 체인을 다 사용하면 인덱스 증가n
보다 크거나 같으면 break
!!