코드
풀이 설명
- 입력된 동전들의 조합 list를 구한다. (조합들의 합, set (중복 제거) 사용)
- 해당 list를 순회하며 count(1->2->...) 변수와 함께 검사한다.
- 1씩 증가하는 count 변수와 맞지 않는 list item이 나오면,
count 변수에 해당하는 자연수가 비어있는 것으로 간주하고 count를 출력한다.
from itertools import combinations
from itertools import chain
n = int(input())
data = list(map(int, input().split()))
count = 0
cdata = []
for i in range(1, n):
temp = combinations(data, i)
temp = map(lambda x: sum(x), temp)
cdata.append(temp)
cdata = list(set(chain(*cdata)))
for num in cdata:
count += 1
if count != num:
print(count)
break
if num == cdata[-1]:
print(count+1)
이코테 정답 코드
n = int(input())
data = list(map(int, input().split()))
data.sort()
target = 1
for x in data:
if target < x:
break
target += x
print(target)