1763: 最大连续子段和

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:30 Solved:17

Description

        给你一个有n个整数的数组 nums ,请你找出其中一个最大的连续子段和(子段和最少包含一个元素),返回其最大和。
      例如,给定9个整数的nums数组为[ -21-34-121-54 ],其中[ 4-121]的和为6,是此数组中的最大连续子段和。

Input

第一行是一个整数,表示序列的长度 lns="http://www.w3.org/1998/Math/MathML">

第二行有 lns="http://www.w3.org/1998/Math/MathML"> 个整数,第 lns="http://www.w3.org/1998/Math/MathML"> 个整数表示nums数组的第 lns="http://www.w3.org/1998/Math/MathML"> 个数字

Output

输出一个数, 为nums数组中的最大连续子段和。

Sample Input Copy

9 
-2 1 -3 4 -1 2 1 -5 4
 

Sample Output Copy

6

HINT

  • 对于 lns="http://www.w3.org/1998/Math/MathML">40% 的数据,保证 lns="http://www.w3.org/1998/Math/MathML">2×103
  • 对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,保证 lns="http://www.w3.org/1998/Math/MathML">12×105lns="http://www.w3.org/1998/Math/MathML">