Pagini recente » Cod sursa (job #1019092) | Cod sursa (job #3267620) | Cod sursa (job #1624884) | Cod sursa (job #558761) | Cod sursa (job #2538974)
#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;
}