코딩
1486. 장훈이의 높은 선반 D4 파이썬
무는빼주세요
2020. 8. 23. 12:59
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
from itertools import combinations
T=int(input())
for test in range(1,T+1):
N, Height = map(int,input().split())
heightlist = list(map(int,input().split()))
heights=set()
heightlist.sort()
tempmin=99999
for i in range(1,N+1):
combs = list(combinations(heightlist,r=i))
for j in combs:
heights.add(sum(j))
if Height in heights:
answer = 0
else :
for i in heights:
if 0< i-Height < tempmin:
tempmin=i-Height
answer = tempmin
print('#{} {}'.format(test, answer))