Pagini recente » Cod sursa (job #2936875) | Cod sursa (job #2736063) | Cod sursa (job #158110) | Cod sursa (job #2788208) | Cod sursa (job #384892)
Cod sursa(job #384892)
#include <stdio.h>
long long v[100001],p[100001];
long long s;
int main()
{
long n,k,i,c=0,j,x,l=1,t,y,a;
freopen("branza.in","r",stdin);
freopen("branza.out","w",stdout);
scanf("%lld%lld%lld",&n,&a,&t);
v[1]=10000001;
for (i=1;i<t+1;i++)
{
scanf("%lld%lld",&x,&y);
++c;
while ((x<v[c-1]+(i-p[c-1])*a)&&(c>1)) {--c;}
v[c]=x;p[c]=i;s+=v[l]*y;
}
for (i=i;i<n+1;i++)
{
if (p[l]==i-t) ++l;
scanf("%lld%lld",&x,&y);
++c;
while ((x<v[c-1]+(i-p[c-1])*a)&&(c>l)) {--c;}
v[c]=x;p[c]=i;s+=(v[l]+(i-p[l])*a)*y;
}
printf("%lld",s);
return 0;
}