Pagini recente » Cod sursa (job #1634386) | Cod sursa (job #729786) | Cod sursa (job #956778) | Cod sursa (job #2876630) | Cod sursa (job #309406)
Cod sursa(job #309406)
program market;
var
n, c, i, j, k, max, min, pr, tmax, l, tmin: longint;
t, p: array[1..2010] of longint;
f: text;
begin
assign(f, 'carnati.in');
reset(F);
max:=0;
readln(f, n, c);
for i:= 1 to n do
readln(f, t[i], p[i]);
{ for i:= 1 to n do
for j:= i to n do
if t[i]>t[j] then
begin
tmp:=t[i];
t[i]:=t[j];
t[j]:=tmp;
tmp:=p[i];
p[i]:=p[j];
p[j]:=tmp;
end;}
for i:=1 to n do
for j:= i to n do
for k:=i to j do
begin
min:=p[k];
tmin:=t[k];
tmax:=t[k];
pr:=0;
for l:=i to j do
if min<=p[l] then
begin
pr:=pr+1;
if t[l]<tmin then
tmin:=t[l];
if t[l]>tmax then
tmax:=t[l];
end;
pr:=min*pr-c*(tmax-tmin+1);
if max<pr then
max:=pr;
end;
close(F);
assign(f, 'carnati.out');
rewrite(F);
writeln(f, max);
close(F);
end.