Cod sursa(job #74239)

Utilizator andrei.12Andrei Parvu andrei.12 Data 24 iulie 2007 12:38:57
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<stdio.h>
#include<stdlib.h>
int n, i, ind, smax, s, m;
struct ors{
	int d, l;
};
ors v[100005];
int comp(const void*a, const void*b){
	ors x = *(ors*)a, y = *(ors*)b;
	if (x.d < y.d) return -1;
	if (x.d > y.d) return 1;
	return 0;
}
int main()
{
	freopen("orase.in","r",stdin);
	freopen("orase.out","w",stdout);
	scanf("%d%d", &m, &n);
	if (n==2)
		return 0;
	for (i=1; i<=n; i++)
		scanf("%d%d", &v[i].d, &v[i].l);
	qsort(v, n+1, sizeof(v[0]), comp);
	smax = 0;
	ind = 0;
	for (i=2; i<=n; i++){
		s = v[i].d+v[i].l;
		if (v[i-1].l-v[i-1].d > ind)
			ind = v[i-1].l-v[i-1].d;
		if (s+ind > smax)
			smax = s+ind;
	}
	printf("%d\n", smax);
	fclose(stdin);
	fclose(stdout);
	return 0;
}