Pagini recente » Cod sursa (job #851799) | Cod sursa (job #874083) | Cod sursa (job #2477530) | Cod sursa (job #1037337) | Cod sursa (job #1003119)
#include <cstdio>
#include <algorithm>
struct client{
int t, p;
} cl[2010];
bool cmp(client a, client b)
{
return a.t<b.t;
}
int main()
{
freopen("carnati.in","r",stdin);
freopen("carnati.out","w",stdout);
int n,c;
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++)
scanf("%d%d",&cl[i].t,&cl[i].p);
long long cost,max=0;
std::sort(&cl[1],&cl[n+1],cmp);
for(int j=1;j<=n;j++)
{
cost=cl[j].p;
long long act=0;
for(int i=1;i<=n;i++)
{
act=act-c*(cl[i].t-cl[i-1].t);
if(cl[i].p>=cost)
{
if(act+cost>cost)
{
act+=cost;
}
else
act=cost;
if(act>max)
{
max=act;
}
}
}
}
printf("%lld",max-c);
return 0;
}