Cod sursa(job #1517581)

Utilizator raulmuresanRaul Muresan raulmuresan Data 4 noiembrie 2015 16:38:04
Problema Carnati Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include<fstream>
#include<algorithm>
#include<vector>
#include <cstring>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");



int n,m,k,i,j,p,x,y,a[100005],t,best[2010],val,sol;
struct coada
{
    int t,p;
};
coada c[2010];

bool cmp(coada i,coada j)
{
    return i.t<j.t;
}
void init()
{
    int i;
    for(i=1;i<=n;i++)
    {
        best[i]=0;
    }
}



int main()
{
    fin>>n>>k;
    for(i=1;i<=n;i++)
    {
        fin>>c[i].t>>c[i].p;

    }
    c[0].t = c[0].p = -2000;
    sort(c+1,c+n+1,cmp);
    sol=0;
    for(i=1;i<=n;i++)
    {
        init();
        val=c[i].p;
        for(j=1;j<=n;j++)
        {
            x=0;
            if(c[j].p >= val)
            {
                x=val;
            }
            best[j]=best[j-1]-(c[j].t-c[j-1].t)*k+x;
            best[j]=max(best[j],x-k);
            best[j]=max(best[j],0);
            sol=max(sol,best[j]);

           /* value = D[j - 1] - (v[j].first - v[j - 1].first) * c + x;
            D[j] = max(value, x - c);
            ans = max(ans, D[j]);*/
        }
    /*fout<<val<<"------";
        for(j=1;j<=n;j++)
        {
            fout<<best[j]<<" ";
        }
        fout<<"\n";*/

    }
    fout<<sol<<"\n";
    for(i=1;i<=n;i++)
    {
     //   fout<<c[i].t<<" "<<c[i].p<<"\n";
    }
}