#P3971. [TJOI2014] Alice and Bob
[TJOI2014] Alice and Bob
Description
Alice and Bob invented a new game. Given a sequence , Alice gets a sequence , where is the length of the longest increasing subsequence ending at ; Bob gets a sequence , where is the length of the longest decreasing subsequence starting at . Alice’s score is the sum of the sequence , and Bob’s score is the sum of the sequence .
Input Format
The first line contains , and the second line contains the sequence . It is guaranteed that the sequence can be obtained from at least one permutation of to .
Output Format
Output a single line indicating the highest score Bob can obtain given the sequence .
4
1 2 2 3
5
4
1 1 2 3
5
Hint
Constraints
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号