#P1854. [IOI 1999] 花店橱窗布置

[IOI 1999] 花店橱窗布置

Description

A flower shop currently has FF 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 1V1 \sim V, where VV is the number of vases.

The bouquets can be moved, and each bouquet is identified by an integer 1F1 \sim F. All bouquets must maintain the order of their identifiers when placed into vases. For example, suppose azalea has identifier 11, begonia has identifier 22, and carnation has identifier 33; 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 ai,ja_{i,j}). The aesthetic value of an empty vase is 00. 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 77 2323 5-5 24-24 1616
Begonia 55 2121 4-4 1010 2323
Carnation 21-21 55 20-20 2020

According to the table, placing the azalea in vase 22 looks very good, but placing it in vase 44 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 FF and VV, the number of bouquets and the number of vases.

Then follows the matrix ai,ja_{i,j} with FF rows and VV integers per row, where ai,ja_{i,j} denotes the aesthetic value of placing bouquet ii into vase jj.

Output Format

On the first line, output a single integer, the maximum total aesthetic value.
On the second line, output FF integers p1,p2,,pFp_1, p_2, \dots, p_F, where pip_i is the index of the vase that holds bouquet ii. All placed bouquets must satisfy: if i<ji < j, then pi<pjp_i < p_j.

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 100%100\% of the testdata, 1FV1001 \le F \le V \le 100.
  • Thanks to @Luo Kai for providing the SPJ.

Translated by ChatGPT 5