Cod sursa(job #2791812)

Utilizator WtfIsThisNeagu Andrei WtfIsThis Data 31 octombrie 2021 09:42:15
Problema Jocul Flip Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.08 kb
#include <iostream>
#include <fstream>
#include <vector>

// NU MI A IESIT BINE

using namespace std;

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

int main(){
    long int N, M, sumapozcol, sumanegcol, sumapoz, sumaneg, neutru, sumamax1=0, sumamax2=0;
    vector<int> cifra(1000000);
    fin >> N >> M;

    for(int i=1; i<=N; i++){
        sumapoz = sumaneg = neutru = sumapozcol = sumanegcol = 0;
        for(int k=1;k<=M;k++){
            fin >> cifra[k];
            if(cifra[k] >= 0)
                sumapoz += cifra[k];
            else
                sumaneg += -cifra[k];        
        }
        if(sumaneg > sumapoz){
            neutru = sumapoz;
            sumapoz = sumaneg;
            sumaneg = neutru;
        }
        for(int l=1;l<=N*M;l+=M){
            fin >> cifra[l];
            if(cifra[l] >= 0)
                sumapozcol += cifra[l];
            else
                sumanegcol += -cifra[l];
        }
        neutru=0;
        if(sumanegcol > sumapozcol){
            neutru = sumapozcol;
            sumapozcol = sumaneg;
            sumanegcol = sumapoz;
        }
        sumamax1 += sumapoz - sumaneg + sumapozcol - sumanegcol;
    }

    for(int i=1; i<=N; i++){
        sumapoz = sumaneg = neutru = sumapozcol = sumanegcol = 0;
        for(int l=1;l<=N*M;l+=M){
            fin >> cifra[l];
            if(cifra[l] >= 0)
                sumapozcol += cifra[l];
            else
                sumanegcol += -cifra[l];
        }
        if(sumanegcol > sumapozcol){
            neutru = sumapozcol;
            sumapozcol = sumaneg;
            sumanegcol = sumapoz;
        }
        for(int k=1;k<=M;k++){
            fin >> cifra[k];
            if(cifra[k] >= 0)
                sumapoz += cifra[k];
            else
                sumaneg += -cifra[k];        
        }
        neutru=0;
        if(sumaneg > sumapoz){
            neutru = sumapoz;
            sumapoz = sumaneg;
            sumaneg = neutru;
        }
        sumamax2 += sumapoz - sumaneg + sumapozcol - sumanegcol;
    }

    if(sumamax1 >= sumamax2)
        fout << sumamax1;
    else fout << sumamax2;
}