Cod sursa(job #1119844)

Utilizator margikiMargeloiu Andrei margiki Data 24 februarie 2014 20:20:27
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
# include <fstream>
# include <algorithm>
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
struct elem
{
    int timp,price;
}a[2005];
int cmp (elem x, elem y)
{
    if (x.timp>=y.timp) return 0;
        else return 1;
    return 1;
}
int i,j,n,SAL,pret,G,maxx,var[2005];
int main ()
{
    f>>n>>SAL;
    for (i=1; i<=n; ++i)
        f>>a[i].timp>>a[i].price;
    sort (a+1,a+n+1,cmp);
    maxx=-999999; var[0]=-999999;
    for (i=1; i<=n; ++i)
    {
        pret=a[i].price;
        for (j=1; j<=n; ++j)
        {
            if (a[j].price>=pret) G=pret;
                else G=0;
            var[j]=max(var[j-1]-(a[j].timp-a[j-1].timp)*SAL+G,G-SAL);
            maxx=max(maxx,var[j]);
        }
    }
    g<<maxx<<"\n";
    return 0;
}