-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOTD-Make Matrix Beautiful.cpp
60 lines (48 loc) · 1.17 KB
/
POTD-Make Matrix Beautiful.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
//Function to find minimum number of operations that are required
//to make the matrix beautiful.
int findMinOpeartion(vector<vector<int>> matrix, int n)
{
vector<int> values(n);
int need = 0;
for(int i = 0; i < n; i++){
int row, col;
row = col = 0;
for(int j = 0; j < n; j++){
row += matrix[j][i];
col += matrix[i][j];
}
need = max({need, row, col});
values[i] = row;
}
int ans = 0;
for(auto i : values)
ans += need - i;
return ans;
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<vector<int> > matrix (n,vector<int>(n));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>matrix[i][j];
Solution ob;
cout << ob.findMinOpeartion(matrix, n) << endl;
}
return 0;
}
// } Driver Code Ends