commit a9cf62ae5201b0d4f8dd5a2727719a112fcbe30c parent 4c4488067228a6eadc6f183bcdb58962fde2f454 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Thu, 25 Jul 2024 22:59:43 +0200 1 Random Problem Diffstat:
A | Problems/1975.cpp | | | 18 | ++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Problems/1975.cpp b/Problems/1975.cpp @@ -0,0 +1,18 @@ +class Solution { + public: + long long maxMatrixSum(const vector<vector<int>> &matrix) const { + const int n = size(matrix); + int count = 0, mini = INT_MAX; + long long res = 0; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + res += abs(matrix[i][j]); + count += matrix[i][j] < 0; + mini = min(mini, abs(matrix[i][j])); + } + } + + return count % 2 == 0 ? res : res - 2 * mini; + } +}; diff --git a/README.md b/README.md @@ -1035,6 +1035,7 @@ for solving problems. | 1965 | Easy | [Employees With Missing Information](Problems/1965.cpp) | | 1970 | Hard | [Last Day Where You Can Still Cross](Problems/1970.cpp) | | 1971 | Easy | [Find if Path Exists in Graph](Problems/1971.cpp) | +| 1975 | Medium | [Maximum Matrix Sum](Problems/1975.cpp) | | 1976 | Medium | [Number of Ways to Arrive at Destination](Problems/1976.cpp) | | 1978 | Easy | [Employees Whose Manager Left the Company](Problems/1978.cpp) | | 1980 | Medium | [Find Unique Binary String](Problems/1980.cpp) |