Cod sursa(job #1914618)

Utilizator DobosDobos Paul Dobos Data 8 martie 2017 17:41:31
Problema Carnati Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>
#define NMAX 2005

using namespace std;

ifstream fin("carnati.in");
ofstream fout("carnati.out");

struct client{
    int h,p;
};

struct cmp{
    bool operator()(const client &a,const client &b){
        return a.h < b.h;
    }
};


client V[NMAX];

int D[NMAX];

int main()
{
    ios :: sync_with_stdio(false);

    int n,C,sol = 0;

    fin >> n >> C;

    for(int i = 1; i <= n; i++){
        fin >> V[i].h >> V[i].p;
    }

    sort(V + 1,V + n + 1,cmp());

    V[0].h = V[1].h - 1;
    V[0].p = 0;

    for(int i = 1; i <= n; i++){

        for(int j = 1; j <= n; j++){
            if(V[j].p >= V[i].p)
                D[j] = max(max(V[i].p - C,0) ,D[j - 1] + V[i].p - (V[j].h - V[j - 1].h) * C);
            else
                D[j] = max(0,D[j - 1] - (V[j].h - V[j - 1].h) * C);

            sol = max(sol,D[j]);
        }




    }

    fout << sol;

    return 0;
}