Pagini recente » Cod sursa (job #1511611) | Cod sursa (job #2975841) | Cod sursa (job #1030916) | Cod sursa (job #3240595) | Cod sursa (job #29737)
Cod sursa(job #29737)
#include<stdio.h>
//#include<conio.h>
long a[100][100],b[100],c[100],s1=-1000000,s2;
int n,m,g,h,w,w1,s,max,bol=1;
void check()
{
//check sum h
for(g=0;g<n;g++)
{
s=0;
for(h=0;h<m;h++)
s=s+a[g][h];
b[g]=s;
}
//check sum v
for(g=0;g<m;g++)
{
s=0;
for(h=0;h<n;h++)
s=s+a[h][g];
c[g]=s;
}
//check max
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];
}
}
/*void cout()
{
for(g=0;g<n;g++)
{
for(h=0;h<m;h++)
printf("%d ",a[g][h]);
printf("\n");
}
printf("_________\n%d - %d\n________\n\n",s1,s2);getch();
}*/
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("%d",&a[g][h]);
}
}
//cout();
//vvvvvvvvvvvvvvvvvvvvv
while(s1<s2)
{
check();
if(w==0)
flipg(w1);
else
fliph(w1);
//cout();
if(bol==0)
s1=sum();
else
s2=sum();
if(bol==0)
bol=1;
else
bol=0;
}
//^^^^^^^^^^^^^^^^^^^^^
printf("%l",s1);
//getch();
return 0;
}