Pagini recente » Cod sursa (job #2748266) | Cod sursa (job #2345561) | Cod sursa (job #390195) | Cod sursa (job #1632295) | Cod sursa (job #2853001)
#include <bits/stdc++.h>
using namespace std;
ifstream in("flip.in");
ofstream out("flip.out");
int n, m;
int mat[17][17], i, j, ma, s;
int pos1, pos2;
int main(){
in>>n>>m;
for(i = 0; i<n; i++){
for(j = 0; j<m; j++) in>>mat[i][j], mat[i][m] += mat[i][j] , mat[n][j] += mat[i][j];
}
ma = 99999999;
for(j = 0; j<m; j++) if(mat[n][j] < ma) ma = mat[n][j], pos1 = j;
ma = 99999999;
for(i = 0; i<n; i++) if(mat[n][i] < ma) ma = mat[i][m], pos2 = i;
// out<<pos1<<" "<<pos2;
for(i = 0; i<n; i++){
for(j = 0; j<m; j++){
if(j == pos1 || i == pos2) mat[i][j] *= -1;
s += mat[i][j];
}
}
out<<s;
}