Three Investigators
Time limit5sMemory limit512 MB
For each prefix length k, find the maximum total sum of at most 5 disjoint non-decreasing subsequences taken from that prefix.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Array
- Solved
- No attempts yet
Problem
Chitanda owns a sequence of integers, and she wants to play a game with Skywalkert.
First, Chitanda selects a parameter and removes . Then exactly integers remain in the sequence .
Next, Skywalkert can select a subsequence of and remove it from . If the selected subsequence is , then and must hold.
Skywalkert can perform this operation at most 5 times. His score is the sum of all integers he selects in these operations.
For each possible parameter that Chitanda selects, find the maximum score Skywalkert can achieve.
Input
The first line contains an integer (), the number of test cases.
Each test case has one line with an integer (), the length of the sequence. The next line contains integers ().
The sum of over all test cases is at most 500000.
Output
For each test case, print one line with integers separated by spaces, where is the maximum score Skywalkert can achieve when .