Cod sursa(job #851401)
| Utilizator | Data | 9 ianuarie 2013 22:40:15 | |
|---|---|---|---|
| Problema | Carnati | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int i,n,cost,x,u,s,c,j,sol=-100000;
struct cl
{
int t,p;
};
cl a[2001];
int main()
{
f>>n>>c;
for(i=1;i<=n;++i)
f>>a[i].t>>a[i].p;
sort(a+1,a+n+1);
a[0].t=a[0].p=-1000;
for(i=1;i<=n;++i)
{
s=0;
for(j=1;j<=n;++j)
{
cost=a[i].p;
x=cost-(a[j].t-a[j-1].t)*c;
if(s+x<cost-c)
s=cost-c;
else
s=s+x;
sol=max(sol,s);
}
}
g<<sol<<"\n";
return 0;
}
