SWEA

5215. 햄버거 다이어트

zhelddustmq 2024. 7. 15. 20:42

문제: 무단 배포 금지로 인해 사이트 주소로 남깁니다.

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWT-lPB6dHUDFAVT

 

정답 코드:

from itertools import combinations
T = int(input())
for test_case in range(1, T + 1):
    N, L = map(int, input().split())
    arr = [list(map(int, input().split())) for _ in range(N)]
    #갓성비
    best = 0
    for i in range(1, N+1):
        for combination in combinations(arr, i):
            calorie = 0
            taste = 0
            #칼로리와 맛 계산
            for j in range(i):
                taste += combination[j][0]
                calorie += combination[j][1]
            #칼로리값 넘어가면 패스
            if calorie > L:
                continue
            best = max(best, taste)
    print(f"#{test_case}", best)