Pagini recente » Profil numai_eu | Profil revup | Profil AGMinformatica | Profil max_tuudor | Cod sursa (job #332907)
Cod sursa(job #332907)
var t,p:array[1..2000] of longint;
n,c,i,m,b2,pmax,pmax2,x:longint;
f,g:text;
function val(pr:longint):word;
begin
if pr>=x then
val:=1
else
val:=0;
end;
begin
assign(f,'carnati.in');
assign(g,'carnati.out');
reset(f);rewrite(g);
readln(f,n,c);
for i:=1 to n do
readln(f,t[i],p[i]);
pmax2:=-maxlongint;
for m:=1 to n do
begin
x:=p[m];
pmax:=val(p[1])*x-c;
b2:=pmax;
for i:=2 to n do
begin
if b2+c*(t[i-1]-t[i]+1)>=0 then
b2:=b2+val(p[i])*x+t[i-1]*c-t[i]*c
else
b2:=val(p[i])*x-c;
if b2>pmax then
pmax:=b2;
end;
if pmax>pmax2 then
pmax2:=pmax;
end;
if pmax2>0 then
write(g,pmax2)
else
write(g,0);
close(f);close(g);
end.