#C10691. Maximum Subsequence Sum
Maximum Subsequence Sum
Maximum Subsequence Sum
Given an array of integers, your task is to compute the maximum sum of any non-empty subsequence. A subsequence is obtained by choosing some (or all) elements from the array without changing their original order.
If the array contains at least one positive integer, the maximum sum is the sum of all positive integers. Otherwise, if all the numbers are non-positive, the result is the maximum number in the array.
Formally, let \(A = [a_1, a_2, \dots, a_n]\) be the array. The answer \(S\) is defined as follows:
\[ S = \begin{cases} \sum_{i=1}^{n}\max(a_i,0), & \text{if } \exists\, a_i > 0, \\ \max_{1 \leq i \leq n} a_i, & \text{otherwise.} \end{cases} \]Input is read from standard input and output should be written to standard output.
inputFormat
The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single integer: the maximum sum of any non-empty subsequence of the array.
## sample6
3 -1 4 1 -5 9
17