Cod sursa(job #125381)

Utilizator slayer4uVictor Popescu slayer4u Data 20 ianuarie 2008 12:44:54
Problema Inundatii Scor 0
Compilator cpp Status done
Runda preONI 2008, Runda 3, Clasa a 10-a Marime 0.71 kb
#include <stdio.h>
#include <algorithm>
using namespace std;

long i, j, n, num;

struct lol
{
	long a, b, c;
};
lol x[50100];

int cmpf(lol b, lol a)
{
	if (a.a >= b.a)
	{
		num += (a.a - b.a + 1);
		b.a = a.a + 1;
	}
	
	if (a.b >= b.b)
	{
		num += (a.b - b.b + 1);
		b.b = a.b + 1;
	}
	
	if (a.c >= b.c)
	{
		num += (a.c - b.c + 1);
		b.c = a.c + 1;
	}
	return (a.a < b.a && a.b < b.b && a.c < b.c);
}

int main()
{
	freopen ("inundatii.in", "rt", stdin);
	freopen ("inundatii.out", "wt", stdout);

	scanf("%ld", &n);
	for (i = 1; i <= n; i ++)
	{
		scanf("%ld %ld %ld", &x[i].a, &x[i].b, &x[i].c);
	}

	sort(x + 1, x + n + 1, cmpf);

	printf("%ld\n", num);

	return 0;
}