URL
https://leetcode.com/problems/maximum-matrix-sum/description/?envType=daily-question&envId=2024-11-24
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202411/maximum_matrix_sum/main.fsx
let maxMatrixSum (matrix: int[,]) : int64 =
matrix
|> Seq.cast<int>
|> Seq.map int64
|> Seq.fold
(fun (sum, negatives, minVal) n -> sum + abs n, (negatives + if n < 0 then 1 else 0), min minVal (abs n))
(0L, 0, System.Int64.MaxValue)
|> fun (sum, negatives, minVal) -> if negatives % 2 = 0 then sum else sum - 2L * minVal