Pagini recente » Cod sursa (job #275560) | Cod sursa (job #2374111) | Cod sursa (job #2262954) | Cod sursa (job #908188) | Cod sursa (job #29742)
Cod sursa(job #29742)
#include<stdio.h>
//#include<conio.h>
long a[20][20],b[20],c[20],s1=-1000000,s2;
int n,m,g,h,w,w1,s,max,bol=1;
void check()
{
for(g=0;g<n;g++)
{
s=0;
for(h=0;h<m;h++)
s=s+a[g][h];
b[g]=s;
}
for(g=0;g<m;g++)
{
s=0;
for(h=0;h<n;h++)
s=s+a[h][g];
c[g]=s;
}
max=0;
for(g=0;g<n;g++)
if(b[g]<max)
{max=b[g];w=0;w1=g;}
for(g=0;g<m;g++)
if(c[g]<max)
{max=c[g];w=1;w1=g;}
}
int sum()
{
int suma=0;
for(g=0;g<n;g++)
for(h=0;h<m;h++)
suma=suma+a[g][h];
return suma;
}
void flipg(int q)
{
for(h=0;h<m;h++)
{
a[q][h]=0-a[q][h];
}
}
void fliph(int q)
{
for(g=0;g<n;g++)
{
a[g][q]=0-a[g][q];
}
}
int main()
{
FILE *f;
f=freopen("flip.in","r",stdin);
freopen("flip.out","w",stdout);
scanf("%d",&n);scanf("%d",&m);
for(g=0;g<n;g++)
{
for(h=0;h<m;h++)
{
scanf("%l",&a[g][h]);
}
}
while(s1<s2)
{
check();
if(w==0)
flipg(w1);
else
fliph(w1);
if(bol==0)
s1=sum();
else
s2=sum();
if(bol==0)
bol=1;
else
bol=0;
}
printf("%l",s1);
return 0;
}