#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 nn and mm whose product does not exceed 2×1052 \times 10^5; nn is the number of members of your treasure hunting team, and mm is the number of treasure items. The members and items are numbered 1 through nn and 1 through mm, respectively. The ii-th of the following nn lines has mm positive integers not exceeding 2×1052 \times 10^5 in descending order: vi,1vi,2vi,mv_{i,1} \geq v_{i,2} \geq \cdots \geq v_{i,m}. Here, vi,jv_{i,j} is the value of the item jj estimated by the member ii.

输出格式

If you can distribute the items to the members without making any member angry, output such a distribution in a line as mm positive integers x1,x2,,xmx_1, x_2, \dots, x_m separated by spaces. Here, xj=ix_j = i means that the member ii receives the item jj. 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 Vi(X)V_i(X) denote the sum of the values of items in the set XX estimated by the member ii.

In Sample 1, V1({1,3})V_1(\{1,3\}) is 4+1=54 + 1 = 5, V1({2})V_1(\{2\}) is 2, V2({1,3})V_2(\{1,3\}) is 3+3=63 + 3 = 6, and V2({2})V_2(\{2\}) is 3. The distribution shown as output does not make the member 1 angry as V1({1,3})V1({2})V_1(\{1,3\}) \geq V_1(\{2\}). The member 2 does not get angry either even though V2({2})<V2({1,3})V_2(\{2\}) < V_2(\{1,3\}) 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 V2({1})=3V_2(\{1\}) = 3 or V2({3})=3V_2(\{3\}) = 3, neither of which is higher than V2({2})=3V_2(\{2\}) = 3.

Note that their shares should not be exchanged. Suppose that the member 1 receives {2}\{2\} and the member 2 receives {1,3}\{1,3\}. This makes the member 1 angry because V1({2})=2<4=V1({1})V_1(\{2\}) = 2 < 4 = V_1(\{1\}) holds, meaning that, even if the member 2 waives the item 3, which is estimated to be the lesser of {1,3}\{1,3\}, the value of the sole remaining item 1 is still estimated higher than V1({2})=2V_1(\{2\}) = 2.

In Sample 2, you are the sole member of your team, so you can take them all. Congratulations!