Pagini recente » Cod sursa (job #893722) | Cod sursa (job #2409520) | Cod sursa (job #887829) | Cod sursa (job #902240) | Cod sursa (job #2538899)
#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;
}