Cod sursa(job #1267239)

Utilizator gedicaAlpaca Gedit gedica Data 19 noiembrie 2014 17:58:29
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
#include <algorithm>

using namespace std;

const int NMAX= 50000;

ifstream in( "orase.in" );
ofstream out( "orase.out" );

struct oras
{
    int x, y;
};

oras v[NMAX+1];

int cmp( oras a, oras b)
{
    return a.x < b.x;
}

int main(  )
{
    int M, N;
    in >> M >> N;

    for( int i=1; i<=N; ++i )
    {
        in >> v[i].x >> v[i].y;
    }

    sort( v+1, v+N+1, cmp );

    int aux= 1, ans= 0, poz= v[1].y-v[1].x;
    for( int i=2; i<=N; ++i )
    {
        if( ans<v[aux].y + v[i].y + ( v[i].x-v[aux].x ) )
        {
            ans= v[aux].y+v[i].y+( v[i].x-v[aux].x );
        }
        if( poz<v[i].y-v[i].x )
        {
            poz= v[i].y-v[i].x;
            aux= i;
        }
    }
    out << ans;
    return 0;
}