不是VIP会员,不能显示答案

题目解答

题目:
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
考点: 0
分析:
解答: B 数组的值为0 3 7 5 13 3
C 数组的值为0 0 0 0 0 0
ans为差最大
评论:
老师: 0