Cod sursa(job #1492186)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 27 septembrie 2015 11:42:35
Problema Inundatii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <algorithm>
#include <cstring>
#include <vector>

#define DIM 50005
#define infile "inundatii.in"
#define outfile "inundatii.out"

using namespace std;

ifstream fin(infile);
ofstream fout(outfile);

int x[DIM], y[DIM], z[DIM];

int modul(const int &x) {

	if (x < 0) {

		return -x;

	}

	return x;

}

int main() {

	int n;

	fin >> n;

	for (int i = 1; i <= n; ++i) {

		fin >> x[i] >> y[i] >> z[i];

	}


	int med = n / 2 + 1;

	long long solution = 0;

	for (int i = 1; i <= n; ++i) {

		solution += modul(x[med] + i - med - x[i]);

		solution += modul(y[med] + i - med - y[i]);

		solution += modul(z[med] + i - med - z[i]);

	}


	fout << solution;

	return 0;

}

//Trust me, I'm the Doctor!