Pagini recente » Cod sursa (job #889060) | Cod sursa (job #2403561) | Cod sursa (job #1516536) | Cod sursa (job #3250955) | Cod sursa (job #2719321)
#include <fstream>
#include<algorithm>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int n,m,c,prof,dp[2005],maxx,minn;
struct om
{
int t,p;
}v[2005];
bool cmp(om x, om y)
{
return x.t<y.t||x.t==y.t&&x.p>y.p;
}
int main()
{
fin>>n>>c;
for(int i=1;i<=n;i++)
{
fin>>v[i].t>>v[i].p;
}
sort(v+1,v+n+1,cmp);
int tmax=v[n].t;
for(int i=1;i<=n;i++)
{
prof=v[i].p;
for(int j=1;j<=n;j++)
if(v[j].p>=prof)
dp[v[j].t]+=prof;
dp[0]-=c;
for(int j=1;j<=tmax;j++)
dp[j]+=dp[j-1]-c;
minn=0;
for(int j=1;j<=tmax;j++)
{
minn=min(minn,dp[j]);
maxx=max(maxx,dp[j]-minn);
}
for(int j=0;j<=tmax;j++)
dp[j]=0;
}
fout<<maxx;
return 0;
}