Cod sursa(job #1279139)

Utilizator diana97Diana Ghinea diana97 Data 29 noiembrie 2014 20:28:50
Problema Inundatii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f ("inundatii.in");
ofstream g ("inundatii.out");

const int NMAX = 50000 + 1;

int n;
int x[NMAX], y[NMAX], z[NMAX];

void citeste() {
    f >> n;
    for (int i = 1; i <= n; i++) {
        f >> x[i] >> y[i] >> z[i];
    }
}

inline int modul(int x) {
    if (x >= 0) return x;
    return -x;
}

long long rezolva(int x[]) {
    int mijloc = (1 + n) / 2 , m = x[mijloc] - mijloc;
    long long sol = 0;
    for (int i = 1; i <= n; i++)
        sol += modul(x[i] - i - m);
    return sol;
}


int main() {
    citeste();
    long long sol = rezolva(x) + rezolva(y) + rezolva(z);
    g << sol << '\n';
    return 0;
}