Cod sursa(job #937111)

Utilizator Athena99Anghel Anca Athena99 Data 9 aprilie 2013 19:38:27
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <cassert>
#include <cstdio>

const int nmax=1000005;
int c[nmax],d[nmax];

int max(int a,int b)
{
    if (a>b)
        return a;
    return b;
}

int main()
{
    int n=0,m=0,i=0,x=0,y=0,maxim=0;

    assert(freopen("orase.in","r",stdin));
    assert(freopen("orase.out","w",stdout));

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

    for (i=0; i<n; ++i)
    {
        assert(scanf("%d%d",&x,&y));
        maxim=max(maxim,d[x]+y);
        d[x]=max(d[x],y);
    }

    i=0;
    while (d[i]==0)
        ++i;

    ++i;
    while (i<=m)
    {
        c[i]=max(c[i-1],d[i-1])+1;
        ++i;
    }

    for (i=0; i<nmax; ++i)
        maxim=max(maxim,c[i]+d[i]);

    assert(printf("%d\n",maxim));

    return 0;
}