Cod sursa(job #2677352)

Utilizator Turica_Andrei_CosminTurica Andrei Turica_Andrei_Cosmin Data 26 noiembrie 2020 12:13:10
Problema Jocul Flip Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include<fstream>
using namespace std;
int main()
{
    ifstream g("flip.in");
    ofstream f("flip.out");
    long i,j,N,M,a[20][20],max=0,x,s;
    g>>N>>M;
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=M;j++)
        {
            g>>a[i][j];
        }
    }
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=M;j++)
        {
            x=x+a[i][j];
            if(x<max) max = x;;
        }
    }
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=M;j++)
        {
            x=a[i][j];
            if(x==max)
            {
                a[i][j]=a[i][j]-1;
                break;
            }
        }
    }
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=M;j++)
        {
            if(a[i][j]>0) s=s+a[i][j];
        }
    }
    f<<s;
    return 0;

}