Cod sursa(job #1734088)

Utilizator antracodRadu Teodor antracod Data 26 iulie 2016 14:38:52
Problema Orase Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;

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

struct str
{
    int x,y;
}v[50000];

struct str_cmp
{
    bool operator() (const str &x,const str &y)
    {
        return x.x<y.x;
    }
};

int main()
{
    int m,n;
    int lmax=0,sol=0;
    int i,j;

    in>>m>>n;

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

    sort(v+1,v+n+1,str_cmp());
    lmax=v[1].y;
    v[0].x=0;
    for(i=2;i<=n;i++)
    {
        lmax=lmax+v[i].x-v[i-1].x;

        if(lmax+v[i].y>sol)
        {
            sol=lmax+v[i].y;

        }
        if(lmax<v[i].y)
        {
            lmax=v[i].y;

        }
    }
    out<<sol;

}