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)

'SWEA' 카테고리의 다른 글

1215. [S/W 문제해결 기본] 3일차 - 회문1  (0) 2024.07.16
1210. [S/W 문제해결 기본] 2일차 - Ladder1  (2) 2024.07.16
2007. 패턴 마디의 길이  (0) 2024.07.15
1284. 수도 요금 경쟁  (0) 2024.07.15
1945. 간단한 소인수분해  (0) 2024.07.15