Pagini recente » Cod sursa (job #2253996) | Cod sursa (job #2271657) | Cod sursa (job #2676945) | Cod sursa (job #163552) | Cod sursa (job #490852)
Cod sursa(job #490852)
#include<stdio.h>
#include<algorithm>
using namespace std;
const int inf=2000000000;
int n,sal;
struct client
{
int t,p;
};
client v[1501];
void citire()
{
scanf("%d%d",&n,&sal);
for (int i=1;i<=n;++i)
scanf("%d%d",&v[i].t,&v[i].p);
}
int val(int pret)
{
int sc,smax,u,i,deficit;
sc=0;
smax=-inf;
u=-1;
for (i=1;i<=n;++i)
{
if (v[i].p<pret)
continue;
if (u!=-1)
deficit=(v[i].t-u-1)*sal;
else
deficit=0;
if (sc<deficit)
sc=0;
else
sc-=deficit;
sc=pret+sc-sal;
if (sc>smax)
smax=sc;
u=v[i].t;
}
return smax;
}
bool comp(client x, client y)
{
return x.t<y.t;
}
int main()
{
freopen("carnati.in","r",stdin);
freopen("carnati.out","w",stdout);
citire();
int i,x,max=-inf;
sort(&v[1],&v[1+n],comp);
for (i=1;i<=n;++i)
{
x=val(v[i].p);
if (max<x) max=x;
}
printf("%d",max);
return 0;
}