Assign cranes to buildings so each building's tower ends with lifting power at least its target, minimizing the output lexicographically.
Medium7GreedySortingDynamic programmingImplementationNo attempts yetTime limit4sMemory limit512 MBHigh rise buildings in the Knightsbridge shopping district go up with cranes. Standing a crane on the ground works for a low building, but a skyscraper would need a crane just as tall, so the trade mounts a smaller crane on top of the tower instead. That raises the next question. How does the crane get to the top? A smaller crane lifts it. If that smaller crane is still too heavy, an even smaller one lifts that, and so on down to a crane light enough for an engineer to carry up in a pocket.
You have N cranes. Crane i weighs Wi kilograms and lifts at most Li kilograms. You also have M buildings under construction. Building i is served when the crane standing on its top at the end lifts Ti kilograms.
The rules on one building are these.
Find a plan that serves every building.
If the buildings cannot all be served, print impossible.
Otherwise print M lines. Line i holds the indices of the cranes raised onto building i, in the order they are raised, separated by single spaces.
Several plans can serve every building. Print the smallest one under this rule. Compare the first lines of two plans as sequences of integers. The smaller plan is the one holding the smaller number at the first position where the two lines differ, and if the numbers agree up to the point where one line ends, the shorter line is smaller. If the first lines are identical, compare the second lines the same way, then the third, and so on.