Cod sursa(job #1002661)

Utilizator heracleRadu Muntean heracle Data 28 septembrie 2013 14:22:23
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <cstdio>
#include <algorithm>

struct client{
int timp, pret;
} cl[2010];

bool cmp(client x, client y)
{
    return x.timp<y.timp;
}

int main()
{
    freopen("carnati.in","r",stdin);
    freopen("carnati.out","w",stdout);

    int n,c;
    scanf("%d%d",&n,&c);

    for(int i=1;i<=n;i++)
        scanf("%d%d",&cl[i].timp,&cl[i].pret);

    long long cost,max=0;
    std::sort(&cl[1],&cl[n+1],cmp);
    for(int h=1;h<=n;h++)
    {
        cost=cl[h].pret;
        long long act=0;
        for(int i=1;i<=n;i++)
        {
            act=act-c*(cl[i].timp-cl[i-1].timp);
            if(cl[i].pret>=cost)
            {
                if(act+cost>cost)
                {
                    act+=cost;
                }
                else
                    act=cost;

                if(act>max)
                {
                    max=act;
                }
            }
        }
    }
    printf("%lld",max-c);
    return 0;
}