Pagini recente » Istoria paginii runda/simlotvrancea2010baraj1/clasament | Cod sursa (job #1814390) | Cod sursa (job #1849103) | Cod sursa (job #2708110) | Cod sursa (job #1989285)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fi("flip.in");
ofstream fo("flip.out");
int main()
{
int n, m, a[1000][1000], b[1000][100];
fi>>n>>m;
for(int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
fi>>a[i][j];
b[i][j] = a[i][j];
}
int s_1 = 0;
for(int i = 0; i < n; i++)
{
int s_local_1 = 0, s_local_2 = 0;
for (int j = 0; j < m; j++)
{
s_local_1 += a[i][j];
}
for (int j = 0; j < m; j++)
{
s_local_2 = s_local_2 + (a[i][j]*(-1));
}
if (s_local_1 < s_local_2)
{
for (int j = 0; j < m; j++)
a[i][j] *= -1;
}
}
for(int i = 0; i < m; i++)
{
int s_local_1 = 0, s_local_2 = 0;
for (int j = 0; j < n; j++)
{
for (int j = 0; j < n; j++)
{
s_local_1 += a[j][i];
}
for (int j = 0; j < n; j++)
{
s_local_2 = s_local_2 + (a[j][i]*(-1));
}
if (s_local_1 < s_local_2)
{
for (int j = 0; j < n; j++)
a[j][i] *= -1;
}
}
}
for(int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
s_1 += a[i][j];
////////////////////////
int s_2 = 0;
for(int i = 0; i < m; i++)
{
int s_local_1 = 0, s_local_2 = 0;
for (int j = 0; j < n; j++)
{
for (int j = 0; j < n; j++)
{
s_local_1 += a[j][i];
}
for (int j = 0; j < n; j++)
{
s_local_2 = s_local_2 + (a[j][i]*(-1));
}
if (s_local_1 < s_local_2)
{
for (int j = 0; j < n; j++)
a[j][i] *= -1;
}
}
}
for(int i = 0; i < n; i++)
{
int s_local_1 = 0, s_local_2 = 0;
for (int j = 0; j < m; j++)
{
s_local_1 += a[i][j];
}
for (int j = 0; j < m; j++)
{
s_local_2 = s_local_2 + (a[i][j]*(-1));
}
if (s_local_1 < s_local_2)
{
for (int j = 0; j < m; j++)
a[i][j] *= -1;
}
}
for(int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
s_2 += a[i][j];
if(s_1 > s_2)
fo<<s_1;
else
fo<<s_2;
fo.close();
return 0;
}