Cod sursa(job #80038)

Utilizator Darth_NiculusIvan Nicolae Darth_Niculus Data 25 august 2007 16:54:30
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
/* Ivan Nicolae - Bucuresti */
/* Infoarena - Orase */
#include <stdio.h>
#include <string.h>

#define NMAX 50001
#define _fin  "orase.in"
#define _fout "orase.out"
#define Infinity (0x3f3f3f3f)

int i,j,n,m,L[NMAX],D[NMAX];

void QuickSort(int li, int ls)
{
 int i=li,j=ls,x=D[(li+ls)/2],y;

 while (i<=j)
      {
       while (D[i] < x) i++;
       while (D[j] > x) j--;
       if (i<=j)
         {
          y=D[i]; D[i]=D[j]; D[j]=y;
          y=L[i]; L[i]=L[j]; L[j]=y;
          i++; j--;
         }
      }   
 if (i<ls) QuickSort(i,ls);
 if (li<j) QuickSort(li,j);
}

int main(void)
{
 freopen(_fin,"r",stdin);
 freopen(_fout,"w",stdout);

 scanf("%d%d",&m,&n);

 for (i=1;i<=n;i++)
    scanf("%d%d",&D[i],&L[i]);

 QuickSort(1,n);

 int max=-1,max_rez=-Infinity;
 for (i=1;i<=n;i++)
    {
     if (D[i]+L[i]+max > max_rez)
       max_rez=D[i]+L[i]+max;
     if (L[i]-D[i]>max)
       max=L[i]-D[i]; 
    }

 printf("%d\n",max_rez);

 fclose(stdin);
 fclose(stdout);
 return 0;
}