Pagini recente » Cod sursa (job #3223403) | Cod sursa (job #211661) | Cod sursa (job #957423) | Cod sursa (job #1833097) | Cod sursa (job #309403)
Cod sursa(job #309403)
program Carnati;
var
n,m,c,i,j,k,s,mn,i1,max1,j1,tt,ss,sst,mm,inc1,inc2:longint;
t,p:array[0..2000] of longint;
fl:text;
procedure qsort(in1,in2:longint);
var
x,i,j:longint;
begin
x:=t[(in1+in2) div 2];
i:=in1;
j:=in2;
while i<j do
begin
while x>t[i] do
i:=i+1;
while x<t[j] do
j:=j-1;
if i<=j then
begin
k:=t[i];
t[i]:=t[j];
t[j]:=k;
k:=p[i];
p[i]:=p[j];
p[j]:=k;
i:=i+1;
j:=j-1;
end;
end;
if j>in1 then
qsort(in1,j);
if i<in2 then
qsort(i,in2);
end;
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);
qsort(1,n);
s:=0;
tt:=0;
mm:=0;
t[0]:=0;
p[0]:=0;
for i := 1 to n do
begin
mm:=0;
for j := 1 to n do
begin
if p[j]>=p[i] then
i1:=p[i]
else
i1:=0;
ss:=i1+mm-(t[j]-t[j-1])*c;
if ss<i1-c then
ss:=i1-c;
if ss>max1 then
max1:=ss;
mm:=ss;
end;
end;
assign(fl,'carnati.out');
rewrite(fl);
writeln(fl,max1);
close(fl);
end.