Pagini recente » Cod sursa (job #1207394) | Cod sursa (job #2096041) | Cod sursa (job #393576) | Cod sursa (job #2143572) | Cod sursa (job #33101)
Cod sursa(job #33101)
#include<fstream.h>
long a[300][20];
int main(){
ifstream fin("flip.in");
ofstream fout("flip.out");
short m;
int n;
long S,S1,max=0,P=0;
fin>>n>>m;
for (int i=0;i<n;i++)
for (short j=0;j<m;j++)
fin>>a[i][j];
short ok=0;
while (ok==0){
ok=1;
for (int h=0;h<n;h++) {
S=0;
S1=0;
for (short u=0;u<m;u++){
S+=(-1)*a[h][u];
S1+=a[h][u];}
if (S>S1) {
for (short g=0;g<m;g++)
a[h][g]=a[h][g]*(-1);
ok=0;}
else
if (S==(-1)*S1){
for (short r=0;r<m;r++){
S=0;
S1=0;
for (int z=0;z<n;z++){
S+=(-1)*a[z][r];
S1+=a[z][r];}
if (S>S1) {
for (int c=0;c<n;c++)
a[c][r]=a[c][r]*(-1);
ok=0;}
else
for (int l=0;l<n;l++)
a[h][l]=a[h][l]*(-1);} }
P=0;}
for (int w=0;w<n;w++)
for (short j=0;j<m;j++)
P+=a[w][j];
if (P>max)
max=P; }
fout<<max;
fin.close();
fout.close();
return 0;
}