最小值错了6个点
var f1,f2:ARRAY[1..100,1..100,1..100] of LONGINT;
g1,g2,ju:array[1..100,1..100] of longint;
a:array[0..101] of longint;
i,j,k,x,y,n:longint;
begin
read(n);
for i:=1 to n do
begin
read(a[i]);
f1[i,i,1]:=a[i];
f2[i,i,1]:=a[i];
end;
for i:=1 to n do
for j:=1 to n do
if i<>j then
g2[i,j]:=maxlongint;
for i:=2 to n do
for j:=1 to n do
for k:=1 to n do
if f1[j,k,i-1]<>0 then begin
x:=j-1;if x=0 then x:=n;
y:=k+1;if y=n+1 then y:=1;
if g1[x,k]<=f1[j,k,i-1]+a[x]+g1[j,k] then begin
g1[x,k]:=f1[j,k,i-1]+a[x]+g1[j,k];
f1[x,k,i]:=f1[j,k,i-1]+a[x]; end;
if g1[j,y]<=f1[j,k,i-1]+a[y]+g1[j,k]
then begin
g1[j,y]:=f1[j,k,i-1]+a[y]+g1[j,k];
f1[j,y,i]:=f1[j,k,i-1]+a[y];end;
end;
for i:=2 to n do
for j:=1 to n do
for k:=1 to n do
if f2[j,k,i-1]<>0 then begin
x:=j-1;if x=0 then x:=n;
y:=k+1;if y=n+1 then y:=1;
if g2[j,k]=maxlongint then
g2[j,k]:=0;
if g2[x,k]>=f2[j,k,i-1]+a[x]+g2[j,k] then begin
g2[x,k]:=f2[j,k,i-1]+a[x]+g2[j,k];
f2[x,k,i]:=f2[j,k,i-1]+a[x];
if i=n then ju[x,k]:=1; end;
if g2[j,y]>=f2[j,k,i-1]+a[y]+g2[j,k]
then begin
g2[j,y]:=f2[j,k,i-1]+a[y]+g2[j,k];
f2[j,y,i]:=f2[j,k,i-1]+a[y];
if i=n then ju[j,y]:=1;
end;
end;
x:=-1000;
y:=maxlongint;
for i:=1 to n do
for j:=1 to n do begin
if x<=g1[i,j] then x:=g1[i,j];
if (y>=g2[i,j])and(ju[i,j]<>0)and(g2[i,j]<>0) then y:=g2[i,j]; end;
writeln(y);
write(x);
end.
最大值都对
最小值错了6个点