From 46e04ed6509726e5e18bfc305d805d66fd657e95 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sun, 7 Sep 2025 21:05:47 +0900 Subject: [PATCH] 20250907 baekjoon --- code_study/Baekjoon/swift/2096.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 code_study/Baekjoon/swift/2096.swift diff --git a/code_study/Baekjoon/swift/2096.swift b/code_study/Baekjoon/swift/2096.swift new file mode 100644 index 0000000..f023a8e --- /dev/null +++ b/code_study/Baekjoon/swift/2096.swift @@ -0,0 +1,23 @@ +if let N = Int(readLine() ?? "") { + var maxSum: [Int] = [0,0,0] + var minSum: [Int] = [0,0,0] + for _ in 1...N { + if let input = readLine(), + let nums = input.split(separator: " ").compactMap({Int($0)}) as? [Int], + nums.count == 3 + { + let a = nums[0]; let b = nums[1]; let c = nums[2] + let tempMax = maxSum; let tempMin = minSum + + maxSum[0] = max(tempMax[0], tempMax[1]) + a + maxSum[1] = (tempMax.max() ?? 0) + b + maxSum[2] = max(tempMax[1], tempMax[2]) + c + + minSum[0] = min(tempMin[0], tempMin[1]) + a + minSum[1] = (tempMin.min() ?? 0) + b + minSum[2] = min(tempMin[1], tempMin[2]) + c + } + } + + print(maxSum.max() ?? 0, minSum.min() ?? 0) +}