#P9160. multiset
multiset
Background
ZHY has many sets. When there are many sets, they become a multiset.
Problem Description
Given a multiset (elements in the set may repeat) , find the largest multiset such that is a proper subset of , and for every element in , either has no predecessor in , or the predecessor of in . If there are multiple sets with the same maximum size that satisfy the conditions, then choose the one with the largest sum of all elements. Output the size of and the sum of its elements.
The predecessor of a number in a set is defined as the maximum element among all elements in with .
Input Format
The first line contains a positive integer , representing the size of .
The second line contains positive integers, representing the elements in .
Output Format
Output one line with two integers. The first number is the size of , and the second number is the sum of all elements in .
4
4 5 1 4
3 10
6
1 4 2 8 5 7
5 19
Hint
Sample 1 Explanation
is .
Sample 2 Explanation
is .
Constraints
For of the testdata, .
For of the testdata, , and elements in .
Translated by ChatGPT 5