Pagini recente » Cod sursa (job #2585472) | Cod sursa (job #1836516) | Cod sursa (job #1231360) | Cod sursa (job #2465172) | Cod sursa (job #332820)
Cod sursa(job #332820)
var t,p:array[1..2000] of longint;
n,c,i,max,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>=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;
write(g,pmax2);
close(f);close(g);
end.