Cod sursa(job #460024)

Utilizator mathboyDragos-Alin Rotaru mathboy Data 31 mai 2010 23:33:00
Problema Orase Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <algorithm>

#define nmax 50010
#define DIM2 8142
using namespace std;

struct lol { int L, D; } A[nmax];
int i, n, m, sol, maxL;
inline bool cmp (const lol &a, const lol &b) {
	return a.D < b.D;
}
char vec[DIM2];
int poz;
void cit(int &x)   
{   
  x=0;   
  while(vec[poz]<'0' || vec[poz]>'9')   
       if(++poz==DIM2) fread(vec,1,DIM2,stdin),poz=0;   
  
    while(vec[poz]>='0' && vec[poz]<='9')   
    {   
        x=x*10+vec[poz]-'0';   
        if(++poz==DIM2) fread(vec, 1, DIM2, stdin),poz=0;   
    }  
}   
int main () {
	freopen ("orase.in", "r", stdin);
	freopen ("orase.out", "w", stdout);
	scanf ("%d%d\n", &n, &m);
	for (i = 1; i <= n; i++)
		cit (A[i].D), cit (A[i].L);
	//random_shuffle (A + 1, A + n + 1);
	sort (A + 1, A + n + 1, cmp);
	sol = -nmax;
	for (i = 1; i <= n; i++) {
		if (sol < A[i].L + A[i].D + maxL) sol = A[i].L + A[i].D + maxL;
		if (maxL < A[i].L - A[i].D) maxL = A[i].L - A[i].D;
	}
	printf ("%d\n", sol);
	return 0;
}