Dream Team
View as PDFThe MAPS sports committee could not agree on which events to include in its relay, so it included
all of them. Welcome to the -athlon:
different legs, ranging from running and swimming to
whatever sport the committee discovers next.
Your team has exactly people, numbered from
to
. The legs must be completed in order
from
to
, with exactly one person completing each leg and each person competing exactly
once. Person
takes
seconds to complete leg
. Each leg starts as soon as the
previous leg finishes, and changing competitors takes no time.
Everyone wants to compete in their favourite event. You would prefer to win.
Choose an order for your team that minimises the total time needed to complete all legs.
Input
The first line contains an integer (
), the number of people and the number
of legs.
Each of the next lines contains
integers. The
-th integer on the
-th of these lines
is
(
), the time in seconds that person
takes to complete
leg
.
Output
Print space-separated integers
, where
is the person assigned
to leg
. Every integer from
to
must appear exactly once.
The sum must be as small as possible.
If several orders achieve the minimum total time, print any of them.
Example 1
Input
3
1 2 9
2 9 9
9 1 2
Output
2 1 3
Explanation
Assigning people ,
, and
to the three legs takes
seconds.
Although person
is fastest at the first leg, assigning them there would prevent
this minimum total.
Example 2
Input
1
7
Output
1
Explanation
There is only one person and one leg, so there is only one possible order.
Example 3
Input
2
5 5
5 5
Output
2 1
Explanation
Both orders take seconds. The order
1 2 would also be accepted.
Comments