Cod sursa(job #2538974)

Utilizator rd211Dinucu David rd211 Data 5 februarie 2020 14:27:25
Problema Inundatii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
	
#include <iostream>
 #include <fstream>
using namespace std;
ifstream fin("inundatii.in");
ofstream fout("inundatii.out");
const int NMAX = 50010;
int n;
int X[NMAX], Y[NMAX], Z[NMAX];
int main()
{
    fin>>n;
    for(int i = 1; i<=n; i++)
        fin>>X[i]>>Y[i]>>Z[i];
    int answer = 0;
    int turningPoint = n/2;
    int xLeft = X[turningPoint]-1, xRight = X[turningPoint]+1;
    int yLeft = Y[turningPoint]-1, yRight = Y[turningPoint]+1;
    int zLeft = Z[turningPoint]-1, zRight = Z[turningPoint]+1;
    for(int i = 1;i<turningPoint;i++)
    {
        answer+=abs(X[i]-xLeft);
        xLeft--;
        answer+=abs(Y[i]-yLeft);
        yLeft--;
        answer+=abs(Z[i]-zLeft);
        zLeft--;
    }
    for(int i = turningPoint+1;i<=n;i++)
    {
        answer+=abs(X[i]-xRight);
        xRight++;
        answer+=abs(Y[i]-yRight);
        yRight++;
        answer+=abs(Z[i]-zRight);
        zRight++;
    }
    fout<<answer;
    return 0;
}