| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
谁来看看,自己觉得都考虑全了(CODE)var
l,r,s:array[0..100000] of longint;
i,max,n,sum:longint;
function fmax(a,b,c:longint):longint;
begin
if (a>=b)and(a>=c) then fmax:=a
else if (b>=a)and(b>=c) then fmax:=b
else if (c>=a)and(c>=b) then fmax:=c;
end;
begin
readln(n);
while n<>0 do
begin
for i:=1 to n do read(s[i]);
readln;
fillchar(l,sizeof(l),0);
fillchar(r,sizeof(r),0);
l[0]:=0;
l[1]:=s[1];
r[n-1]:=s[n];
r[n]:=0;
sum:=s[1];
for i:=2 to n do
begin
if sum<0 then
begin
sum:=s[i];
l[i]:=s[i];
end
else
begin
sum:=sum+s[i];
l[i]:=sum;
end;
end;
sum:=s[n];
max:=sum;
for i:=n-2 downto 0 do
begin
r[i]:=fmax(sum,s[i+1],sum+s[i+1]);
if max>r[i] then r[i]:=max;
if sum<0 then sum:=s[i+1]
else sum:=sum+s[i+1];
if sum>max then max:=sum;
end;
max:=-maxlongint;
for i:=0 to n do
if l[i]+r[i]>max then max:=l[i]+r[i];
writeln(max);
readln(n);
end;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator