#P3860. [TJOI2009] 火星人的手机
[TJOI2009] 火星人的手机
Description
To input a letter, we must press its numeric key several times consecutively; the number of presses equals the letter’s position on that key. For example, in the scheme above, to input C, we press numeric key 2 three times; to input M, we press numeric key 6 once.
The Martian phone is similar to the Earth phone: it has Martian numeric keys, and you need to place the letters of the Martian alphabet onto these keys. (Likewise, the letters on any single numeric key must be a contiguous block of Martian letters.) Now, given the occurrence count of each letter in a passage of Martian text, your design must minimize the total number of key presses required to input this passage.
Input Format
The first line of input contains two numbers, and , the number of Martian letters and the number of keys on the Martian phone, respectively. The next lines each contain one number, in order, giving the occurrence count of each letter in the passage. Each count does not exceed .
Output Format
The first line of output contains a single number, the minimum total number of key presses.
The next lines describe one design: each line contains a number, in order, indicating how many Martian letters are placed on each numeric key. (These numbers may be .)
If multiple designs achieve the same minimum, output the one with the fewest letters on the first numeric key; if still tied, among those choose the one with the fewest letters on the second numeric key; and so on.
3 2
100
200
300
800
2
1
Hint
Constraints
For of the data, , .
Translated by ChatGPT 5
京公网安备 11011102002149号