본문 바로가기

알고리즘/백준 (Pyhthon)

[알고리즘] 백준 2798 블랙잭

n, m = input().split()
n = int(n)
m = int(m)
card_num = list(map(int, input().split()))
sum = list()

for i in range(0, n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            sum.append(card_num[i] + card_num[j] + card_num[k])

result = 0
for i in sum:
    if i <= m:
        result = max(result, i)
        
print(result)

 

n, m = list(map(int, input().split(' ')))
data = list(map(int, input().split(' ')))

result = 0

for i in range(0, n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            sum_value = data[i] + data[j] + data[k]
            if sum_value <= m:
                result = max(result, sum_value)
                
print(result)