#ds601. 最大和上升子序列2
最大和上升子序列2
Maximum-Sum Increasing Subsequence 2
Problem Description
You are given an array of length . Find the increasing subsequence with the maximum sum. That is, find indices satisfying and , so as to maximize .
Input Format
The first line contains one number .
The next line contains integers .
Output Format
Output one number, the answer.
Sample Input
6
3 7 4 2 6 8
Sample Output
21
Constraints
For all data, and are guaranteed.