题目: |
var n,i,j,ans:longint;
a,b,c:array[0..1000000] of longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
b[1]:=a[1];
for i:=2 to n do b[i]:=b[i-1]+a[i];
c[0]:=b[0];
for i:=1 to n do
if b[i]<c[i-1] then c[i]:=b[i]
else c[i]:=c[i-1];
for j:=1 to n do
if b[j]-c[j-1]>ans then ans:=b[j]-c[j-1];
writeln(ans);
end.
输入:
5
3 4 -2 8 -10
输出:13
|