Problems > Maximum Sum Increasing Subsequence

Maximum Sum Increasing Subsequence

Difficulty: 1500 6000 ms 128 MB

dp

Find the maximum possible sum of a strictly increasing subsequence.

Input: the first line has N; the second line has the array.

Output: the maximum sum.

Constraints:

  • 1 ≤ N ≤ 2000
  • 1 ≤ ai ≤ 104

Sample Tests

Input 1
5
1 101 2 3 100
Output 1
106
Input 2
1
7
Output 2
7
Input 3
4
4 3 2 1
Output 3
4

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.