Cod sursa(job #974036)

Utilizator thewildnathNathan Wildenberg thewildnath Data 16 iulie 2013 12:49:53
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<stdio.h>
#include<algorithm>
using namespace std;

int v[1000002];

int main()
{
    freopen("orase.in","r",stdin);
    freopen("orase.out","w",stdout);
    int n,m,i,sol=0,x,y,d,p;
    scanf("%d%d",&m,&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d",&x,&y);
        v[x]=max(v[x],y);
    }
    i=0;
    while(v[i]==0)
        ++i;
    d=v[i];
    p=i;
    ++i;
    for(;i<=m;++i)
    {
        if(v[i]==0)
            continue;
        if(d+i-p+v[i]>sol)
            sol=d+i-p+v[i];
        if(v[i]>d+i-p)
        {
            d=v[i];
            p=i;
        }
    }
    printf("%d\n",sol);
    return 0;
}