← ~/試題
P2001

Maximum Subarray

Medium
// 描述
Given an array of n integers, find the contiguous subarray (containing at least one number) with the largest sum and output that sum.
// 輸入格式
The first line contains an integer n (1 <= n <= 10^5). The second line contains n integers a_i (-10^4 <= a_i <= 10^4).
// 輸出格式
A single integer: the maximum subarray sum.
// 提示
Kadanes algorithm runs in O(n).
// 樣例
輸入樣例
9
-2 1 -3 4 -1 2 1 -5 4
輸出樣例
6
// 題目資訊
難度Medium
通過率50%
時間限制1000 ms
記憶體限制65536 KB
通過5