
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)