https://www.acmicpc.net/problem/2798
2798번: 블랙잭
첫째 줄에 카드의 개수 N(3 ≤ N ≤ 100)과 M(10 ≤ M ≤ 300,000)이 주어진다. 둘째 줄에는 카드에 쓰여 있는 수가 주어지며, 이 값은 100,000을 넘지 않는 양의 정수이다. 합이 M을 넘지 않는 카드 3장
www.acmicpc.net
파이썬에서 제공하는 순열 조합 라이브러리의 combinations 함수를 이용하여 3개의 카드 조합의 경우를 구했다.
** itertools
https://docs.python.org/ko/3/library/itertools.html
itertools — 효율적인 루핑을 위한 이터레이터를 만드는 함수 — Python 3.10.7 문서
itertools — 효율적인 루핑을 위한 이터레이터를 만드는 함수 이 모듈은 APL, Haskell 및 SML의 구성물들에서 영감을 얻은 여러 이터레이터 빌딩 블록을 구현합니다. 각각을 파이썬에 적합한 형태로
docs.python.org
내 제출
from itertools import combinations
card_num, target_num = map(int,input().split())
card_list = list(map(int,input().split()))
biggest_sum = 0 # 가능한 가장 큰 조합
for cards in combinations(card_list, 3):
temp_sum = sum(cards) # 3장을 더한 값
if biggest_sum < temp_sum <= target_num: # target_num에 가장 가까운 수
biggest_sum = temp_sum
print(biggest_sum)