#P9143. [THUPC 2023 初赛] 众数
[THUPC 2023 初赛] 众数
Problem Description
You have several positive integers in : for , you have copies of the integer . Let .
For a sequence , define its mode as the number that appears the most times. If multiple numbers are tied for the highest frequency, the largest of them is the mode.
Now you need to arrange these numbers into a sequence such that is maximized. Output this maximum value.
Input Format
The first line contains an integer , representing the value range.
The next line contains positive integers , representing the count of each number.
Output Format
Output one positive integer, the maximum value of .
3
1 3 2
17
Hint
Sample Explanation 1
One sequence that achieves the maximum value is .
Constraints
For all testdata, and .
Source
From the 2023 Tsinghua University Student Algorithm Contest and Intercollegiate Invitational (THUPC2023) Preliminary Round.
Solutions and other resources can be found at https://github.com/THUSAAC/THUPC2023-Pre.
Translated by ChatGPT 5