#C7502. Maximum Non-Contiguous Subsequence Sum
Maximum Non-Contiguous Subsequence Sum
Maximum Non-Contiguous Subsequence Sum
Given an array of integers, compute the maximum sum of any non-contiguous subsequence. In this problem, you are allowed to select any subset of the array's elements (in their original order) so that the sum is maximized. Effectively, if an element is positive, it contributes to the sum; if not, it can be skipped. Formally, the answer is given by $$ \text{result} = \sum_{i=1}^{n} \max(0, a_i) $$ where (a_i) are the elements of the array. If none of the numbers are positive, the result is 0. You must read the input from standard input and print the result to standard output.
inputFormat
The input is provided via standard input. The first line contains a single integer (n) representing the number of elements in the sequence. The second line contains (n) space-separated integers.
outputFormat
Output a single integer representing the maximum sum of any non-contiguous subsequence of the given sequence. The output should be written to standard output.## sample
5
3 2 5 10 7
27