Cod sursa(job #2628211)

Utilizator RazvanMVRazvan Vasile RazvanMV Data 14 iunie 2020 23:48:12
Problema Jocul Flip Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <iostream>
#include <fstream>


using namespace std;

ifstream f("flip.in");
ofstream g("flip.out");

int main()
{
    int n,m,i,x,y,w,M[100][16],suma,maxx,h,v[1600],p,j;
    f>>n>>m;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            f>>M[i][j];
        }
    }
    w=n*m;
    for(h=1;h<=w;h++)
    {
        v[h]=0;
        suma=0;
        p=0;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                for(x=1;x<=n;x++)
                {
                    for(y=1;y<=m;y++)
                    {
                        if(i!=x && j!=y)
                        {
                            v[h]=v[h]+M[x][y];
                        }
                        else
                        {
                            p=M[x][y];
                            p = p * (-1);
                            suma=suma+p;
                        }
                    }
                }
                v[h]=v[h]+suma;

            }
        }
    }
    maxx=0;

    for(h=1;h<=w;h++)
    {
        if(v[h]>maxx)
        {
            maxx=v[h];
        }
    }
    g<<maxx;

    return 0;
}