Pagini recente » Cod sursa (job #1452092) | Cod sursa (job #2078772) | Cod sursa (job #127068) | Istoria paginii utilizator/queenalexia | Cod sursa (job #159546)
Cod sursa(job #159546)
var f,g:text;
n,i,j,k,u:word;
c:longint;
s,max,aux,x:longint;
t:array[1..2000] of 1..1500;
p:array[1..2000] of longint;
begin
assign(f,'carnati.in');
reset(f);
assign(g,'carnati.out');
rewrite(g);
read(f,n); readln(f,c);
for i:=1 to n do
begin
read(f,t[i]);
readln(f,p[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if t[i]>t[j] then
begin
aux:=t[i];
t[i]:=t[j];
t[j]:=aux;
aux:=p[i];
p[i]:=p[j];
p[j]:=aux;
end;
max:=0;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
for u:=i to j do
begin
x:=p[u];
s:=0;
for k:=i to j do
begin
if p[k]>=x then s:=s+x;
end;
s:=s-(t[j]-t[i]+1)*c;
if s>max then begin max:=s; end;
end;
end;
write(g,max);
close(f);
close(g);
end.