Cod sursa(job #68906)

Utilizator peanutzAndrei Homorodean peanutz Data 29 iunie 2007 21:09:01
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <stdio.h>
#include <algorithm>
#define NMAX 50000

using namespace std;

typedef struct oras
{
	int d;
	int l;
};
oras a[NMAX+5];
int n, m;

void read()
{
	int i;
	scanf("%d %d", &m, &n);
	for(i = 1; i <= n; ++i)
		scanf("%d %d", &a[i].d, &a[i].l);
}

bool comp(const oras& x, const oras& y)
{
	return (x.d < y.d|| (x.d == y.d && x.l < y.l));
}

int main()
{
    int j, crt, max = -1;
	freopen("orase.in", "r", stdin);
	freopen("orase.out", "w", stdout);

	read();

	sort(a+1, a+n+1, comp);
	
    for(crt = 1, j = 2; j <= n; ++j)
    {
            //printf("%d\n", crt);
            if(a[j].d + a[j].l - a[crt].d + a[crt].l > max)
                      max = a[j].d + a[j].l - a[crt].d + a[crt].l;
            if(a[j].l-a[j].d > a[crt].l-a[crt].d)
                    crt = j;
    }
    printf("%d\n", max);

    //for(int i = 1; i <= n; ++i)
       //   printf("%d %d\n", a[i].d, a[i].l);
	return 0;
}