Kod: Zaznacz cały
program prostokat;
var tab: array[1..200000] of Longint;
tabb: array[1..200000] of Longint;
n,a,i,j,k,r,p,w,z,x: Longint;
begin
for i:=1 to 200000 do
tab[i]:=0;
for i:=1 to 200000 do
tabb[i]:=0;
Read(n);
for i:=1 to 2*n do
begin
Read(a);
if a<0 then a:=(-1)*a;
if i mod 2=1 then tab[i]:=a
else tabb[i]:=a;
end;
r:=0;
for i:=1 to 2*n do
for j:=1 to 2*n do
begin
if tab[i]-tab[j]<0 then r:=(tab[j]-tab[i])
else r:=(tab[i]-tab[j]);
end;
for i:=1 to 2*n do
for j:=1 to 2*n do
begin
w:=0;
if tab[i]-tab[j]<0 then w:=(tab[j]-tab[i])
else w:=(tab[i]-tab[j]);
if w>r then r:=w;
end;
z:=0;
for i:=1 to 2*n do
for j:=1 to 2*n do
begin
if tabb[i]-tabb[j]<0 then z:=(tabb[j]-tabb[i])
else z:=(tabb[i]-tabb[j]);
end;
for i:=1 to 2*n do
for j:=1 to 2*n do
begin
x:=0;
if tabb[i]-tabb[j]<0 then x:=(tabb[j]-tabb[i])
else x:=(tabb[i]-tabb[j]);
if x>z then z:=x;
end;
Write(2*(r-1)+2*(z-1));
end.
Kod: Zaznacz cały
program maksymalna_roznica;
var tab: array[1..500000] of Longint;
r,i,j,n,w: Longint;
begin
Read(n);
r:=0;
for i:=1 to n do Read(tab[i]);
for i:=1 to n do
for j:=1 to n do
begin
w:=0;
if (tab[i]-tab[j])<0 then w:=(tab[j]-tab[i])
else w:=(tab[i]-tab[j]);
if w>r then r:=w;
end;
Write(r);
end.