100 beats and easy solution with Explanation.
Intuition\n Describe your first thoughts on how to solve this problem. \nProblem Breakdown:\nThe goal is to maximize the sum of the matrix by converting negativ
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nProblem Breakdown:\nThe goal is to maximize the sum of the matrix by converting negative values into positive values, but with a few conditions:\n\nNegative Pairing: If there are an even number of negative values, we can convert them all to positive by "multiplying" (or flipping) in pairs. This can be thought of as multiplying negative values with each other and flipping their signs.\nOdd Negative Count: If there are an odd number of negative values, we can convert all but one to positive. The remaining negative value will persist.\nHandling the Remaining Negative: If the remaining negative value is smaller in magnitude than the smallest positive value, we can flip it to make it positive (maximize the sum).\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nDetailed Steps:\nInitial Matrix:\nLet\u2019s take the following matrix as an example:\n\n[-4, 4, 3]\n[ 1, 1, 1]\n[ 2, 5, 4]\n[ 2, 4, -8]\n\nStep-by-Step Explanation:\nInitial Setup:\n\nsum = 0: To track the sum of absolute values.\nMin1 = INT_MAX: To store the smallest absolute value.\nnCount = 0: To count the number of negative values.\nTraverse the Matrix:\n\nFor each element, calculate its absolute value and update sum, Min1, and nCount:\n\nFirst row: [-4, 4, 3]\n\nabs(-4) = 4, sum = 4, Min1 = 4, nCount = 1\nabs(4) = 4, sum = 8, Min1 = 4\nabs(3) = 3, sum = 11, Min1 = 3\nSecond row: [1, 1, 1]\n\nabs(1) = 1, sum = 12, Min1 = 1\nabs(1) = 1, sum = 13, Min1 = 1\nabs(1) = 1, sum = 14, Min1 = 1\nThird row: [2, 5, 4]\n\nabs(2) = 2, sum = 16, Min1 = 1\nabs(5) = 5, sum = 21, Min1 = 1\nabs(4) = 4, sum = 25, Min1 = 1\nFourth row: [2, 4, -8]\n\n[4, 4, 3]\n[ 1, 1, 1]\n[ 2, 5, 4]\n[ 2, 4, 8]\n\nabs(2) = 2, sum = 27, Min1 = 1\nabs(4) = 4, sum = 31, Min1 = 1\nabs(-8) = 8, sum = 39, Min1 = 1, nCount = 2 (two negatives, -4 and -8)\n\nFinal Decision:\nnCount = 2 (even), so we can flip all negative values to positive. The result is simply the sum of absolute values, which is 39.\n\nFinal Result:\nMaximum Sum = 39\n\n\n\n\n# Complexity\n- Time complexity: o(n*m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n![25b9210e-1683-4751-99aa-f9a72307ed16_1702489054.9060743.jpeg](https://assets.leetcode.com/users/images/82e08d72-b33e-49e1-a5ea-13bed48546c9_1732431597.4554706.jpeg)\n\n\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long maxMatrixSum(vector<vector<int>>& m) {\n        long long sum = 0;         \n        int Min1 = INT_MAX;   \n        int nCount = 0;       \n        int temp;\n\n        for (int i = 0; i < m.size(); i++) {\n            for (int j = 0; j < m[0].size(); j++) {\n                if (m[i][j] < 0) \n                    nCount++;\n                temp=abs(m[i][j]);\n                Min1=min(Min1,temp); \n                sum+=temp;   \n               \n            }\n        }\n\n     \n        if (nCount % 2 == 0) {\n            return sum;\n        } \n        return sum-(2*Min1);\n        \n    }\n};\n\n```
['Array', 'Greedy', 'Matrix', 'C++']