Problem list
Log in
#r03327 · Online Judge > GoldOJ

Maximum Subarray Sum

Bronze I 2.0 s 256 MB

Given a sequence of $N$ integers, choose a non-empty contiguous subarray whose sum is maximum, and print that maximum sum.

Input

First line $N$ ($1 \le N \le 100$); second line $N$ integers ($-1000 \le A_i \le 1000$).

Output

Print the maximum contiguous-subarray sum.

Example 1

Input
5
1 -2 3 4 -5
Output
7

Example 2

Input
3
-5 -1 -10
Output
-1

Example 3

Input
10
10 -3 5 10 -20 5 8 -10 20 1
Output
26
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code