Pagini recente » Cod sursa (job #210483) | Cod sursa (job #616838) | Profil DirtuEcaterina | Cod sursa (job #2853145) | Cod sursa (job #1013674)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int n,c;
struct client
{int t,p;};
client cl[2005];
bool comp(client x,client y)
{ if (x.t!=y.t)
return x.t<y.t;
return x.p<y.p;
}
void Read()
{ int i;
f>>n>>c; //cout<<n<<" "<<c;
for(i=1;i<=n;i++)
f>>cl[i].t>>cl[i].p; //cout<<p[1];
sort(cl+1,cl+n+1,comp);
}
int Ans(int price)
{ int i,j,set=0,nri=0,nrj,sol=-(1<<31);
for(i=1;i<=n;i++)
if (price<=cl[i].p)
{ nri++; nrj=0;
for(j=1;j<i;j++)
if (price<=cl[j].p)
{ nrj++;
if (((nri-nrj+1)*price-(cl[i].t-cl[j].t+1)*c)>sol)
sol=((nri-nrj+1)*price-(cl[i].t-cl[j].t+1)*c);
}
if (price-c>sol) sol=price-c;
if (nri*price-c*cl[i].t>sol) sol=nri*price-cl[i].t;
}
return sol;
}
int main()
{ int i,res=-(1<<31);
Read();
for(i=1;i<=n;i++)
res=max(res,Ans(cl[i].p));
g<<res;
return 0;
}