Cod sursa(job #2137158)

Utilizator Paul_BalanPavel Balan Paul_Balan Data 20 februarie 2018 17:20:48
Problema Jocul Flip Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <bits/stdc++.h>

using namespace std;

int N,M,a[17][17],so1,so2,b[17],sv1,sv2,c[17],max1,max2;

int main()
{
    ifstream fin("flip.in");
    ofstream fout("flip.out");

    fin >> N >> M;
    max2 = -1;

while (max1!=max2){
    max1=0;
    for (int i = 1; i<=N; i++){
        for (int j = 1; j<=M; j++){
            fin >> a[i][j];
            so1+=a[i][j];
            so2 = so2 + (-1) * a[i][j];
            b[j] = (-1) * a[i][j];
        }
        if (so2 > so1)
            for (int k=1; k<=M; k++){
                a[i][k] = b[k];
            }
        so1 = so2 = 0;
    }

    for (int j =1; j<=M; j++){
        for (int i =1; i<=N; i++){
            sv1+=a[i][j];
            sv2 = sv2 + (-1) * a[i][j];
            c[i] = (-1) * a[i][j];
        }
        if (sv2 > sv1)
            for (int k=1; k<=N; k++){
                a[k][j] = c[k];
            }
        sv1 = sv2 = 0;
    }

    for (int i = 1; i<=N; i++){
        for (int j = 1; j<=M; j++){
            max1+=a[i][j];
        }
    }
    max2 = max(max1, max2);
}

    fout << max2;

    return 0;
}