PS

2775 파이썬

dlxortmd123 2022. 7. 13. 21:51

n, m = map(int, input().split())
arr = list(map(int, input().split()))
res = 0
for i in range(len(arr)-2):
    for j in range(i+1, len(arr)-1):
        for k in range(j+1, len(arr)):
            temp = arr[i] + arr[j] + arr[k]
            if res < temp <= m:
                res = temp
print(res)

파이썬 내장 순열 이용

import itertools

n, m = map(int, input().split())
arr = list(map(int, input().split()))
res = 0

for cards in itertools.combinations(arr, 3):
    temp = sum(cards)
    if res < temp <= m:
        res = temp
print(res)