20250907 baekjoon
This commit is contained in:
parent
e482f966d5
commit
46e04ed650
23
code_study/Baekjoon/swift/2096.swift
Normal file
23
code_study/Baekjoon/swift/2096.swift
Normal file
@ -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)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user