3
* @GitHub : archit-19974
* @Email : architsingh456@gmail.com5
* @file : maximumMatrixSum.cpp6
* @created : Saturday Aug 21, 2021 20:11:56 IST9
#include <bits/stdc++.h>14
long long maxMatrixSum(vector<vector<int>> &matrix) {15
int r = matrix.size(), c = matrix[0].size();17
// we need to find the min number in the matrix and also count of negative18
// numbers in the matrix19
int small = INT_MAX, count = 0;20
long long int sum = 0;22
for (int i = 0; i < r; i++) {23
for (int j = 0; j < c; j++) {24
int val = matrix[i][j];25
// finding the smallest absolute value in the matrix26
small = min(small, abs(val));27
// counting the negative numbers29
// finding the sum of all the values33
// if even number of negatives, then just return sum37
// subtract the value of the min absolute element38
return sum - 2 * small;