[백준] 2798-블랙잭

kiteday·2025년 7월 16일
0

코딩테스트

목록 보기
14/46

문제바로가기

n개중에 3개를 뽑아서 더한 합이 m을 넘지 않으면 된다.
라이브러리를 이용해 간단하게 조합을 구하고 확인하여 출력하자.

from itertools import combinations
n, m = map(int, input().split())

max_num = 0
num = list(map(int, input().split()))
combi = combinations(num, 3)

for com in combi:
    if sum(com) > max_num and sum(com)<=m:
        max_num = sum(com)       
print(max_num)
profile
공부

0개의 댓글