#t384. 机器分配(assign)

机器分配(assign)

Allocating Machines to Companies

Background

Special for beginners, ^_^

Problem Description

The head office owns MM highly efficient machines and plans to distribute them among its NN branch companies. If a branch company receives these machines, it can generate a certain profit for the country. Question: how to allocate the MM machines so that the profit for the country is maximized? Find the maximum profit value. Here M≤15M \le 15, N≤10N \le 10. Allocation rule: each company may receive any number of machines, but the total number allocated cannot exceed MM. If there are multiple optimal solutions, the earlier companies should receive as few machines as possible.

Input Format

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

This is followed by an N×MN \times M matrix; the value at position (i,j)(i,j) is the profit obtained when the ii-th company is allocated jj machines.

Output Format

The first line is an integer: the maximum profit.

This is followed by NN lines, each with two integers aa and bb, meaning that company aa is allocated bb machines.

Sample Input 1

2 15
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2

Sample Output 1

2
1 0
2 15

Constraints

1s, 1024KiB for each test case.