#P2066. 机器分配

机器分配

Description

The head office has MM high-efficiency machines to distribute to NN subsidiary companies. If a company receives a certain number of machines, it can generate a corresponding profit for the country. How should these MM machines be allocated to maximize the total profit? Find the maximum profit. Constraints: M15M \le 15, N10N \le 10. Allocation rule: each company may receive any number of machines, but the total number cannot exceed MM.

If multiple allocations yield the same maximum profit, break ties by making earlier-indexed companies receive as few machines as possible, that is, minimize x1x_1; if still tied, minimize x2x_2; and so on.

Input Format

The first line contains two numbers: the number of companies NN and the number of machines MM.

Then follows an N×MN \times M matrix. The entry at row ii and column jj gives the profit when company ii is assigned jj machines.

Output Format

The first line contains the maximum profit.

Then output NN lines. In the ii-th line, output the number xx of machines assigned to company ii.

3 3
30 40 50
20 30 50
20 25 30

70
1 1
2 1
3 1

Hint

Translated by ChatGPT 5