找出数组中元素的最大子序列问题,怎么解决

如题所述

var i,n,total,j,temp,ans:longint;
a,b:array[1..100000] of longint;
begin
read(n);
for i:=1 to n do
begin
read(a[i]);
b[i]:=a[i];
total:=total+a[i];
end;
for i:=2 to n do
begin
if a[i]<a[i-1]+a[i]
then a[i]:=a[i-1]+a[i];
if a[i]>ans
then ans:=a[i];
end;
for i:=2 to n do
begin
if b[i]>b[i-1]+b[i]
then b[i]:=b[i-1]+b[i];
if temp>b[i]
then temp:=b[i];
end;
if ans>total-temp
then writeln(ans)
else writeln(total-temp);
end.
温馨提示:答案为网友推荐,仅供参考
相似回答