#P14863. [ICPC 2021 Yokohama R] Distributing the Treasure
[ICPC 2021 Yokohama R] Distributing the Treasure
题目描述
You are the leader of a treasure hunting team. Under your great direction, your team has made a big success in a quest, and got a lot of treasure. The only, but crucial, remaining issue is how to distribute the obtained treasure to the team members.
The excavated treasure includes a variety of precious items: gold ingots, jewelry with brilliant gem stones, exquisite craft works, etc. Each team member individually estimates the values of the items. The estimated values are consistent, in that, for any pair of two items, when some member estimates one to be strictly higher than the other, no member estimates oppositely, although some may give equal estimates.
All the members are sensible and thus understand the difficulty of even distribution of the items. Hence, no member will complain simply because, based on the member’s own estimation, the sum of the values of the member’s share is lower than that of another member’s share. The members, however, may get angry if their own shares look unreasonably shabby compared to some other member’s; what they cannot stand is when their own shares are estimated strictly lower than the share of that other member even after getting rid of one item with the least estimated value.
Your last mission as the leader is to decide who receives which items so that no member gets angry. Some of the members may receive nothing as long as they do not get angry.
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} &n\ m \\ &v_{1,1}\ \cdots\ v_{1,m} \\ &\vdots \\ &v_{n,1}\ \cdots\ v_{n,m} \end{aligned}$$The first line of the input has two positive integers and whose product does not exceed ; is the number of members of your treasure hunting team, and is the number of treasure items. The members and items are numbered 1 through and 1 through , respectively. The -th of the following lines has positive integers not exceeding in descending order: . Here, is the value of the item estimated by the member .
输出格式
If you can distribute the items to the members without making any member angry, output such a distribution in a line as positive integers separated by spaces. Here, means that the member receives the item . If two or more such distributions exist, any of them shall be deemed correct. If there is no way to distribute the items without making any member angry, just output 0 in a line.
2 3
4 2 1
3 3 3
1 2 1
1 7
64 32 16 8 4 2 1
1 1 1 1 1 1 1
提示
Let denote the sum of the values of items in the set estimated by the member .
In Sample 1, is , is 2, is , and is 3. The distribution shown as output does not make the member 1 angry as . The member 2 does not get angry either even though holds. If the member 1 waives one of the two items, the sum of the values of items received by the member 1 would become or , neither of which is higher than .
Note that their shares should not be exchanged. Suppose that the member 1 receives and the member 2 receives . This makes the member 1 angry because holds, meaning that, even if the member 2 waives the item 3, which is estimated to be the lesser of , the value of the sole remaining item 1 is still estimated higher than .
In Sample 2, you are the sole member of your team, so you can take them all. Congratulations!