Pagini recente » Cod sursa (job #2165091) | Cod sursa (job #131225) | Cod sursa (job #1961035) | Cod sursa (job #1578397) | Cod sursa (job #309344)
Cod sursa(job #309344)
program Carnati;
var
n,m,c,i,j,k,s,mn,i1,j1,tt,ss,sst,mm:longint;
t,p:array[0..2000] of longint;
fl:text;
begin
assign(fl,'carnati.in');
reset(fl);
readln(fl,n,c);
for i := 1 to n do
readln(fl,t[i],p[i]);
close(fl);
s:=0;
tt:=0;
mm:=0;
t[0]:=t[1];
p[0]:=p[1];
for i := 1 to n do
for j := i+1 to n do
begin
sst:=0;
tt:=(t[j]-t[i]+1)*c;
for i1 := i to j do
begin
mm:=i1;
ss:=0;
for j1 := i to j do
if p[j1]>=p[mm] then
ss:=ss+p[mm];
if ss>sst then
sst:=ss;
end;
sst:=sst-tt;
if sst>s then
s:=sst;
end;
assign(fl,'carnati.out');
rewrite(fl);
writeln(fl,s);
close(fl);
end.