#t387. 最大上升子序列和
最大上升子序列和
Maximum Increasing Subsequence Sum
Problem Description
For a sequence , when , we call it increasing.
Given a sequence , we can obtain some increasing subsequences where . For example, from the sequence we get increasing subsequences such as and . The largest sum among these is , from the subsequence .
Your task is, given a sequence, to compute the maximum increasing subsequence sum. Note that the longest increasing subsequence need not have the maximum sum; for example, the sequence has maximum increasing subsequence sum , while its longest increasing subsequence is .
Input Format
The first line is the length of the sequence .
The second line gives the integers of the sequence, each in the range to (may repeat).
Output Format
The maximum increasing subsequence sum.
Sample Input
7
1 7 3 5 9 4 8
Sample Output
18