Pagini recente » Cod sursa (job #805632) | Cod sursa (job #2405957) | Cod sursa (job #199666) | Cod sursa (job #1251170) | Cod sursa (job #2538894)
#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];
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 = 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--;
}
fout<<answer;
return 0;
}