Cod sursa(job #2538899)

Utilizator rd211Dinucu David rd211 Data 5 februarie 2020 12:24:57
Problema Inundatii Scor 20
Compilator cpp-64 Status done
Runda simulare_miri Marime 1.08 kb
#include <bits/stdc++.h>

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 = 0; i<n; i++)
        fin>>X[i]>>Y[i]>>Z[i];
    long long finalRes = 12312312312;
    for(int turningPoint = 0;turningPoint<n;turningPoint++){
    long long answer = 0;
    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 = turningPoint+1;i<n;i++)
    {
        answer+=abs(X[i]-xRight);
        xRight++;
        answer+=abs(Y[i]-yRight);
        yRight++;
        answer+=abs(Z[i]-zRight);
        zRight++;
    }
    for(int i = 0;i<turningPoint;i++)
    {
        answer+=abs(X[i]-xLeft);
        xLeft--;
        answer+=abs(Y[i]-yLeft);
        yLeft--;
        answer+=abs(Z[i]-zLeft);
        zLeft--;
    }
        finalRes= min(finalRes, answer);
    }
    fout<<finalRes;
    return 0;
}