Cod sursa(job #2544022)

Utilizator Paul987650Solot Paul Paul987650 Data 11 februarie 2020 18:26:02
Problema Jocul Flip Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <iostream>

std::ifstream cin("flip.in");
std::ofstream cout("flip.out");

int array[16][16] = {};

void maxSum(int n, int m, long long &sum){

    long long sumlinie, sumcoloana;

    for(int i = 0; i < n; i++){
        sumcoloana = 0;
        for(int j = 0; j < m; j++)
            sumcoloana += array[i][j];
        if(sumcoloana < 0){
            for(int j = 0; j < m; j++) {
                array[i][j] = array[i][j] * (-1);
            }
        }
    }

    for(int i = 0; i < m; i++) {
        sumlinie = 0;
        for (int j = 0; j < n; j++)
            sumlinie += array[j][i];
        if (sumlinie < 0) {
            for (int j = 0; j < n; j++) {
                array[j][i] = array[j][i] * (-1);
            }
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++)
            sum += array[i][j];
    }
}

int main()
{
    int n{}, m{};
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> array[i][j];
        }
    }

    long long sum{};

    maxSum(n, m, sum);

    cout << sum << '\n';
}