Pagini recente » Cod sursa (job #764917) | Cod sursa (job #1851473) | Cod sursa (job #2337950) | Cod sursa (job #2171300) | Cod sursa (job #2791812)
#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;
}