Pagini recente » Cod sursa (job #1056594) | Cod sursa (job #744255) | Cod sursa (job #2926876) | Cod sursa (job #334570) | Cod sursa (job #1914618)
#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;
}