Cod sursa(job #828195)
| Utilizator | Data | 3 decembrie 2012 12:57:07 | |
|---|---|---|---|
| Problema | Carnati | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.75 kb |
#include<cstdio>
struct structura
{
int x;
int y;
};
int max,n,c,i,sum,pret,j,pe;
structura v[2001];
int main()
{
freopen("carnati.in","r",stdin);
freopen("carnati.out","w",stdout);
scanf("%d%d",&n,&c);
for(i=1; i<=n; i++)
scanf("%d%d",&v[i].x,&v[i].y);
for(i=1; i<=n; i++)
{
pret=v[i].y;
sum=0;
for(j=1; j<=n; j++)
{
if(sum<0)
{
pe=1;
sum=0;
}
if(v[j].y>=pret)
sum+=pret;
if(!pe)
sum-=(v[j].x-v[j-1].x)*c;
pe=0;
if(sum>max)
max=sum;
}
}
printf("%d",max-c);
}
