Cod sursa(job #991145)

Utilizator enedumitruene dumitru enedumitru Data 29 august 2013 20:55:45
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<fstream>
#include<algorithm> 
#define Nmax 50001
using namespace std;
ifstream f("orase.in"); ofstream g("orase.out");
struct oras {int d,l;} v[50001];
int cmp (oras a,oras b) {return a.d<=b.d;}
int main()
{   int n,m,i;
	f>>m>>n;
    for(i=1;i<=n;++i) f>>v[i].d>>v[i].l;
	sort(v+1,v+n+1,cmp);
    int dist,distmax=0,dif,difmax=v[1].l-v[1].d;
    for(i=2;i<=n;++i)
    {   dist=v[i].l+v[i].d+difmax;
	    if(dist>distmax) distmax=dist;
		dif=v[i].l-v[i].d;
		if(dif>difmax) difmax=dif;
    }
    g<<distmax<<"\n"; g.close(); return 0;
}