Distributing the Treasure
Time limit4sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
You are the leader of a treasure hunting team. Under your direction, the team succeeded in a quest and obtained a lot of treasure. The only remaining issue is how to distribute the treasure among the team members, and it matters.
The treasure includes a variety of precious items: gold ingots, jewelry with brilliant gemstones, exquisite craft works, and so on. Each team member estimates the values of the items individually. The estimates are consistent: for any pair of items, if some member estimates one strictly higher than the other, no member estimates the opposite. Some members may give equal estimates.
All members are sensible and understand that the items cannot be divided evenly. So no member gets angry merely because the sum of the values in their share, by their own estimate, is lower than another member's share. A member does get angry if their own share is estimated strictly lower than another member's share, even after removing the item with the least estimated value from that other share. Some members may receive nothing as long as they do not get angry.
Decide who receives which items so that no member gets angry.
Input
The first line has two positive integers and with . Here is the number of members and is the number of treasure items. Members and items are numbered 1 through and 1 through .
The -th of the following lines contains positive integers, each at most , in descending order: . Here is the value of item estimated by member .
Output
If the items can be distributed without making any member angry, output positive integers separated by spaces, where means member receives item . If several distributions are valid, any of them is accepted.
If no distribution avoids anger, output 0 on a line.
Hint
Let denote the sum of the values of the items in set as estimated by member .
In Sample 1, is , is , is , and is . The output shows a distribution where member 1 is not angry, since . Member 2 is not angry either, even though . If member 1 gives up one of the two items, the remaining share would be worth or , and neither is higher than .
The shares cannot be swapped. Suppose member 1 receives and member 2 receives . Member 1 is angry because . Even if member 2 gives up item 3, the lesser item in , the remaining item 1 is still estimated higher than .
In Sample 2, you are the only member, so you take all the items.