Cod sursa(job #3211392)

Utilizator drsbosDarius Scripcaru drsbos Data 9 martie 2024 11:16:34
Problema Jocul Flip Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("a.in");
ofstream fout("a.out");

int a[20],n,m;
int b[20][20];
int main()
{
    int i, j, total, s, smax = INT_MIN;
    fin >> n >> m;
    for(i = 1;i <= n;i++)
        for(j = 1;j <= m;j++)
            fin >> b[i][j];
    while(a[0] == 0)
    {
        total = 0;
        for(i = 1;i <= n;i++)
        {
            s = 0;
            for(j = 1;j <= m;j++)
                if(a[j] == 0)   s += b[i][j];
                else s -= b[i][j];
            total += abs(s);
        }
        smax = max(smax, total);
        for(j = m;a[j] == 1;j--)
            a[j] = 0;
        a[j] = 1;
    }
    fout << smax << "\n";
    fout.close();
    return 0;
}