Pagini recente » Cod sursa (job #995804) | Cod sursa (job #2712625) | Cod sursa (job #2904052) | Cod sursa (job #91877) | Cod sursa (job #852004)
Cod sursa(job #852004)
#include<fstream>
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int n,c,costmax,cost,i;
struct carnati
{
int t,p;
};
carnati a[2001];
int pret(int cost1)
{
int costmax1=-100,sc=-1,i,costc=0;
for(i=1;i<=n;i++)
{
if(a[i].p<cost)
break;
if(sc!=-1)
{
costc=costc-(a[i].t-a[sc].t-1)*c;
if(costc<0)
costc=0;
}
else
costc=0;
sc=i;
costc=costc+(cost-c);
if(costmax1<costc)
costc=costmax1;
}
return costmax1;
}
int main()
{
f>>n>>c;
for(i=1;i<=n;i++)
f>>a[i].t>>a[i].p;
for(i=1;i<=n;i++)
{
cost=pret(a[i].p);
if(costmax<cost)
costmax=cost;
}
g<<costmax<<" ";
return 0;
}