Cod sursa(job #994864)

Utilizator thewildnathNathan Wildenberg thewildnath Data 6 septembrie 2013 15:28:09
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include<stdio.h>
#include<algorithm>
using namespace std;

typedef struct punct
{
    int x,y;
}punct;

punct v[2002];
int f[1502];
int cmp(punct a,punct b)
{
    if(a.x<b.x)
        return 1;
    if(a.x>b.x)
        return 0;
    if(a.y<b.y)
        return 1;
    return 0;
}

int main()
{
    freopen("carnati.in","r",stdin);
    freopen("carnati.out","w",stdout);
    int n,c,i,j,k,m,M=-2000000000;
    scanf("%d%d",&n,&c);
    for(i=1;i<=n;++i)
        scanf("%d%d",&v[i].x,&v[i].y);
    sort(v+1,v+1+n,cmp);
    for(i=1;i<=n;++i)
    {
        k=1;
        for(j=0;j<=v[n].x;++j)
        {
            f[j]=f[j-1]-c;
            while(v[k].x==j)
                if(v[k++].y>=v[i].y)
                    f[j]+=v[i].y;
        }
        m=0;
        for(j=0;j<=v[n].x;++j)
        {
            m=min(m,f[j]);
            M=max(M,f[j]-m);
        }
    }
    printf("%d\n",M);
    return 0;
}