Pagini recente » Cod sursa (job #2244506) | Cod sursa (job #2801073) | Cod sursa (job #1437486) | Cod sursa (job #2948558) | Cod sursa (job #2032919)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fi("carnati.in");
ofstream fo("carnati.out");
pair <int,int> V[2001];
int n,i,j,pret,profit,s,c,maxim;
int main()
{
fi>>n>>c;
for(i=1;i<=n;i++)
fi>>V[i].first>>V[i].second;
sort(V+1,V+n+1);
for(i=1;i<=n;i++)
{
pret=V[i].second;
s=0;
for(j=1;j<=n;j++)
{
s=max(0,s-c*(V[j].first-V[j-1].first));
if(pret<=V[j].second)
s+=pret;
maxim=max(s-c,maxim);
}
profit=max(maxim,profit);
}
fo<<profit;
fi.close();
fo.close();
return 0;
}