[C++] Explained with Diagram
Logic \n\nIt is clearly mentioned that we can pick any two adjacent cells and mutliply them by -1. Also, this operation can be repeated any number of times.\n\n
### Logic \n\nIt is clearly mentioned that we can pick any two adjacent cells and mutliply them by -1. Also, this operation can be repeated any number of times.\n\n`You may notice that we can change the sign of any two elements just by selecting them and multiplying them by -1. `This means that the position of negative and positive numbers doesn\'t matter because we can definitely reach every cell and perform the same operation. \n\n`Another observation is that for any number, if we do this operation even number of times, then the sign of the element doesn\'t change. `\n\n![image](https://assets.leetcode.com/users/images/54792ad4-4553-4586-83eb-a25b0ed2374c_1629562215.8919232.png)\n\n<br>\n\nBingo !! We will make use of this logic and one by one, make the negative numbers positive as much as we can. \n\n`NOTICE : If there are odd number of positive numbers in the matrix, then no matter what move you chose, you will always end up having one negative number at the end in the complete matrix because at any moment, we will be having odd number of negatives.  `\n\n![image](https://assets.leetcode.com/users/images/90f3314d-293d-48bc-a0ac-27ee387a6beb_1629562245.588995.png)\n\n<br>\n\n\n\n`We can make the smallest number is the matrix negative by performing this operation some x number of times and then we can get the result. `\n\n\n### Approach \n\n1. Find the absolute sum of all the numbers in the matrix\n2. Find the absolute value of the smallest number in the matrix\n3. Count of negative numbers in the matrix\n\n- `If count of negatives is even`, then all elements can be made positive by performing the operation, so just return the total sum of the matrix\n- `If count of negatives is odd`, then we can make the smallest number in the matrix as negative and then return the `sum` \n\t- NOTE : Here the result will be `sum-2*minElement` as you are not including this element. \n\n<br>\n\n##### Please upvote if you like the explanation and the approach\n\n<br>\n\n\n### Accepted Solution\n\n```\n/**\n * @author      : archit\n * @GitHub      : archit-1997\n * @Email       : architsingh456@gmail.com\n * @file        : maximumMatrixSum.cpp\n * @created     : Saturday Aug 21, 2021 20:11:56 IST\n */\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n    long long maxMatrixSum(vector<vector<int>>& matrix) {\n        int r=matrix.size(),c=matrix[0].size();\n\n        //we need to find the min number in the matrix and also count of negative numbers in the matrix\n        int small=INT_MAX,count=0;\n        long long int sum=0;\n\n        for(int i=0;i<r;i++){\n            for(int j=0;j<c;j++){\n                int val=matrix[i][j];\n\t\t\t\t//finding the smallest absolute value in the matrix\n                small=min(small,abs(val));\n\t\t\t\t//counting the negative numbers\n                if(val<0)\n                    count++;\n\t\t\t\t//finding the sum of all the values\n                sum+=abs(val);\n            }\n        }\n\t\t//if even number of negatives, then just return sum\n        if(count%2==0)\n            return sum;\n        else\n\t\t//subtract the value of the min absolute element\n            return sum-2*small;\n    }\n};\n\n```
['Greedy', 'C']