๋ธ๋ก ์ฆ2 : ๋ธ๋ฃจํธํฌ์ค ๋ฌธ์ ์ด๋ค. Code import Foundation func combination<T>(_ elements: [T], _ k: Int) -> [[T]] { var result = [[T]]() func combi(_ index: Int, _ now: [T]) { if now.count == k { result.append(now) return } for i in index..<elements.count { combi(i + 1, now + [elements[i]]) } } combi(0, []) return result } func main() { let input = readLine()! let seps = input.components(separatedBy: " ") let n = Int(seps[0])!, m = Int(seps[1])! var cards = [Int]() cards = readLine()!.components(separatedBy: " ").map { Int($0)! } print(combination(cards, 3).map({ $0.reduce(0, { $0 + $1 })}).filter({ $0 <= m }).max()!) } main() Code2 from itertools import combinations import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) cards = list(map(int, input().split())) summations = list(map(sum, combinations(cards, 3))) print(max(filter(lambda x: x <= m, summations))) if __name__ == "__main__": main() # 10 500 # 93 181 245 214 315 36 185 138 216 295 Reference ๋ฐฑ์ค(2798๋ฒ) -๋ธ๋์ญ