난이도 브론즈2
딜러는 N장의 카드를 고르고 플레이어는 그중 3장을 고른다.
3장의 합이 M보다 크지 않으며 가장 가까운 사람이 승리N(3<=N<=100)
M(10<=M<=300,000)
3중 for문을 사용하여 카드 3장을 고르는 방법
N, M = map(int, input().split())
cards = list(map(int, input().split()))
result=0
for i in range(N):
for j in range(i+1, N):
for k in range(j+1, N):
sum = cards[i] + cards[j] + cards[k]
if sum <= M:
result = max(result, sum)
print(result)
combinations을 사용하여 무작위로 카드 3장을 추출하는 방법
from itertools import combinations
N, M = map(int, input().split())
cards = list(map(int, input().split()))
result = 0 #결과값 초기화
for combo in combinations(cards, 3):
if sum(combo) <=M:
result = max(result, sum(combo))
print (result)
https://www.acmicpc.net/problem/2798
#내맘대로TIL챌린지 #교보DTS #클라우드교육 #글로벌소프트웨어캠퍼스 #GSC신촌
8월부터 재도전!! 8월 챌린지 성공 가보자구용~!!!