Mai intai trebuie sa te autentifici.
Cod sursa(job #773764)
Utilizator | Data | 2 august 2012 15:43:26 | |
---|---|---|---|
Problema | Branza | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.26 kb |
Const
finp='branza.in';
fout='branza.out';
Type
mat=array [0..100000] of longint;
Var q,c,p,a:mat;
t,n,s,f,r:longint;
res:int64;
fi,fo:text;
Procedure Doc;
Var i:longint;
Begin
Assign(fi,finp);
Reset(fi);
Read(fi,n,s,t);
For i:=1 to n do Read(fi,c[i],p[i]);
Close(fi);
end;
Procedure Push(i:longint);
Begin
While (f<=r) and (a[i]<=a[q[r]]) do dec(r);
inc(r);
q[r]:=i;
If q[f]=i-t then inc(f);
end;
Procedure Lam;
Var i:longint;
Begin
f:=1;
r:=0;
For i:=1 to n do
Begin
a[i]:=c[i]-i*s;
Push(i);
res:=res+int64((int64(a[q[f]])+int64(i*s))*int64(p[i]));
end;
end;
Procedure Inkq;
Begin
Assign(fo,fout);
Rewrite(fo);
Write(fo,res);
Close(fo);
end;
Begin
Doc;
Lam;
Inkq;
end.