[백준 2798번][Python/파이썬] 블랙잭

공학도 Lee·2023년 2월 8일
0

백준 문제 풀이

목록 보기
24/63

1. 문제


출처: 백준 2798번 블랙잭

2. 풀이


가능한 조합을 모두 구해서, 블랙잭 변형 규칙을 만족하는 것 중 최선의 값을 찾으면 된다.

python에서 관련해서 활용 가능한 모듈은 itertools.combinations이다.

3. 소스코드


import itertools

N,M = map(int, input().split())
numbers = list(map(int,input().split()))

poss = list(itertools.combinations(numbers,3))
max_value = 0
for i in poss:
    if max_value < sum(i) and sum(i)<=M:
        max_value = sum(i)
print(max_value)

4. 그 외


profile
이창민, Changmin Lee

0개의 댓글