#T53. 橱窗布置
橱窗布置
Description
Suppose we want to arrange the window display of a flower shop in the most aesthetically pleasing way. There are bouquets of flowers, each of a different variety. At the same time, there are at least as many vases, arranged in a row in a fixed order, numbered sequentially from left to right as to , where is the number of vases. Vase number is on the far left, and vase number is on the far right. The bouquets can be moved, and each bouquet is uniquely identified by an integer from to . The integer identifying the bouquet determines the order in which the bouquets are placed in the vases—that is, if , then bouquet must be placed in a vase to the left of bouquet .
For example, suppose the azalea is identified by number , the begonia by number , and the carnation by number . All bouquets must be placed in the vases in the order of their identifiers. That is, 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. If the number of vases is greater than the number of bouquets, the extra vases must remain empty, meaning each vase can hold at most one bouquet.
Each vase also differs in shape and color, so placing different bouquets in different vases will produce varying aesthetic effects, represented by an aesthetic value (an integer). The aesthetic value of an empty vase is . In the example above, the aesthetic values of different vase-bouquet pairings can be represented in the following table.
According to the table, placing the azalea in vase would look very beautiful, but placing it in vase would look very unattractive.
To achieve the best aesthetic effect, the bouquets must be arranged to maximize the total aesthetic value while maintaining the order of the bouquets. If there are multiple arrangements with the maximum aesthetic value, any one of them can be output.
The problem data satisfies the following conditions:
, where is the number of bouquets, numbered from to .
, where is the number of vases.
, where is the aesthetic value of placing bouquet in vase .
Input Format
The first line contains two numbers: , .
The subsequent lines each contain integers, where is the -th number in the -th line of the input file.
Output Format
The first line is the aesthetic value produced by the program's arrangement.
The second line must contain numbers representing the arrangement, where the -th number indicates the vase number in which bouquet is placed.
Vase 1 Vase 2 Vase 3 Vase 4 Vase 5
Azalea 7 23 -5 -24 16
Begonia 5 21 -4 10 23
Carnation -21 5 -4 -20 20
3 5
7 23 –5 –24 16
5 21 -4 10 23
-21 5 -4 -20 20
53
2 4 5