Pagini recente » Cod sursa (job #1828767) | Cod sursa (job #612380) | Cod sursa (job #2317534) | Cod sursa (job #1621557) | Cod sursa (job #2531292)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream x("carnati.in");
ofstream y("carnati.out");
long long n,p,i,prof[2002],profit=-1,j;
struct elem
{
int h,c;
}v[2002];
bool cmp(elem a, elem b)
{
return a.h<b.h;
}
int main()
{
x>>n>>p;
for(i=1;i<=n;i++)
x>>v[i].h>>v[i].c;
sort(v+1,v+n+1,cmp);
v[0].h=v[1].h-1;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
prof[j]=0;
if(v[i].c<=v[j].c)
prof[j]=v[i].c;
prof[j]=max(prof[j]+prof[j-1]-p*(v[j].h-v[j-1].h),prof[j]-p);
if(prof[j]>profit)
profit=prof[j];
}
}
y<<profit;
x.close();
y.close();
return 0;
}