Pagini recente » Cod sursa (job #1067443) | Cod sursa (job #3270259) | Cod sursa (job #3273622) | Cod sursa (job #3275142) | Cod sursa (job #3254271)
#include <bits/stdc++.h>
#define nmx 2005
#define sqr 317
using namespace std;
int n,c;
pair <int,int> v[nmx];
int main()
{
ifstream f ("carnati.in");
ofstream g ("carnati.out");
f>>n>>c;
for (int i=1; i<=n; i++)
f>>v[i].first>>v[i].second;
sort (v+1,v+n+1);
int rsp=0;
for (int l=1; l<=n; l++)
{
int cost=v[l].second,mx=0;
if (cost<=c) continue;
int now=0,prv=v[1].first-1;
//cout<<v[l].second<<'\n';
for (int i=1; i<=n; i++)
{
//cout<<v[i].first<<' ';
if (v[i].second>=cost)
{
now=now-(v[i].first-prv-1)*c;
if (now<0) now=0;
now+=cost-c;
prv=v[i].first;
mx=max(mx,now);
}
//cout<<now<<'\n';
}
//cout<<v[l].second<<' '<<mx<<'\n'<<'\n';
rsp=max(rsp,mx);
}
g<<rsp;
}