#P1854. [IOI 1999] 花店橱窗布置
[IOI 1999] 花店橱窗布置
Description
A flower shop currently has bouquets, each of a different kind. There are at least as many vases, arranged in a row in order. The positions of the vases are fixed and are numbered from left to right as , where is the number of vases.
The bouquets can be moved, and each bouquet is identified by an integer . All bouquets must maintain the order of their identifiers when placed into vases. For example, suppose azalea has identifier , begonia has identifier , and carnation has identifier ; then the azalea must be placed in a vase to the left of the begonia, and the begonia must be placed in a vase to the left of the carnation. Each vase can hold only one bouquet.
Each vase has a unique shape and color, so placing different bouquets in different vases produces different aesthetic effects, represented by an aesthetic value (an integer ). The aesthetic value of an empty vase is . In the above example, the aesthetic values of different pairings of vases and bouquets can be represented by the following table:
| Vase 1 | Vase 2 | Vase 3 | Vase 4 | Vase 5 | |
|---|---|---|---|---|---|
| Azalea | |||||
| Begonia | |||||
| Carnation |
According to the table, placing the azalea in vase looks very good, but placing it in vase looks very bad.
To achieve the best aesthetic effect, under the constraint of preserving the bouquet order, the placement should maximize the total aesthetic value. Every bouquet must be placed into a vase. If there is more than one arrangement that attains the maximum aesthetic value, output any one of them.
Input Format
The first line contains two integers and , the number of bouquets and the number of vases.
Then follows the matrix with rows and integers per row, where denotes the aesthetic value of placing bouquet into vase .
Output Format
On the first line, output a single integer, the maximum total aesthetic value.
On the second line, output integers , where is the index of the vase that holds bouquet . All placed bouquets must satisfy: if , then .
3 5
7 23 -5 -24 16
5 21 -4 10 23
-21 5 -4 -20 20
53
2 4 5
Hint
- The order of bouquet identifiers must be strictly preserved.
- Constraints: For of the testdata, .
- Thanks to @Luo Kai for providing the SPJ.
Translated by ChatGPT 5
京公网安备 11011102002149号