Cod sursa(job #1258586)

Utilizator AlexARAlex Rares AlexAR Data 9 noiembrie 2014 00:47:42
Problema Jocul Flip Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>

using std::ifstream;
using std::ofstream;

int main(){
	int n, m, neg, poz, max = 0;
	int **matrice;

	ifstream input("flip.in");
	ofstream output("flip.out");

	input >> n >> m;

	matrice = new int*[n];

	for (int i = 0; i < n; i++)
		matrice[i] = new int[m];

	for (int j = 0; j < n; j++){
		neg = 0;
		poz = 0;
		for (int i = 0; i < m; i++){
			input >> matrice[i][j];
			if (matrice[i][j]>0)
				poz += matrice[i][j];
			else
				neg += matrice[i][j];
		}

		if (neg*(-1) > poz)
			for (int i = 0; i < m; i++)
				matrice[i][j] *= -1;

	}

	for (int i = 0; i < m; i++){
		neg = 0;
		poz = 0;
		for (int j = 0; j < n; j++){
			if (matrice[i][j]>0)
				poz += matrice[i][j];
			else
				neg += matrice[i][j];
		}

		if (neg*(-1) > poz)
			for (int j = 0; j < n; j++)
				matrice[i][j] *= -1;

	}

	for (int j = 0; j < n; j++)
		for (int i = 0; i < m; i++)
			max += matrice[i][j];

	output << max;


	return 0;

}