Pagini recente » Cod sursa (job #779073) | Cod sursa (job #2659237) | Cod sursa (job #2555104) | Istoria paginii runda/runda_ezoterica_4/clasament | Cod sursa (job #1404130)
#include <iostream>
#include <fstream>
using namespace std;
int n,m;
int tabla[1000][1000];
int invers,normal,maxim=0;
void schimbrand()
{
for(int i=0;i<n;i++)
{
invers=0;
normal=0;
for(int j=0;j<m;j++)
{
normal=normal+tabla[i][j];
invers=invers+tabla[i][j]*(-1);
}
if (invers>normal)
{
for(int j=0;j<m;j++)
{
tabla[i][j]=tabla[i][j]*(-1);
}
}
}
}
void schimbcoloana()
{
for(int j=0;j<m;j++)
{
invers=0;
normal=0;
for(int i=0;i<n;i++)
{
normal=normal+tabla[i][j];
invers=invers+tabla[i][j]*(-1);
}
if (invers>normal)
{
for(int i=0;i<n;i++)
{
tabla[i][j]=tabla[i][j]*(-1);
}
}
}
}
int main()
{
ifstream ifs( "flip.in" );
ofstream ofs( "flip.out" );
ifs>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
ifs>>tabla[i][j];
}
}
schimbrand();
schimbcoloana();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
maxim=maxim+tabla[i][j];
}
}
ofs<<maxim;
}