Knightsbridge Rises

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 MB

Problem

High 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 NN cranes. Crane ii weighs WiW_i kilograms and lifts at most LiL_i kilograms. You also have MM buildings under construction. Building ii is served when the crane standing on its top at the end lifts TiT_i kilograms.

The rules on one building are these.

  • The lifting power available on top is 00 while no crane stands there, and equals the maximum lifting weight of the crane currently on top once one does.
  • You may raise a crane of weight WW onto a building only when the lifting power available there is at least WW. A crane of weight 00 fits in a pocket, so an engineer carries it up, and it can always be the first crane.
  • The crane you raise becomes the crane on top, so the lifting power available there changes to that crane's value.
  • Never raise a crane that fails to increase the lifting power already available there. The lifting powers of the cranes on one building therefore grow from the bottom to the top.
  • A raised crane never moves again. Each crane goes to at most one building, and cranes may be left unused.

Find a plan that serves every building.

Input

  • The first line holds the number of cranes NN (1N1001 \le N \le 100).
  • Each of the next NN lines holds two space separated integers WiW_i and LiL_i (0Wi,Li1060 \le W_i, L_i \le 10^6), the weight and the maximum lifting weight of crane ii in kilograms.
  • The next line holds the number of buildings MM (1M1001 \le M \le 100).
  • The last line holds MM space separated integers T1,T2,,TMT_1, T_2, \dots, T_M (1Ti1061 \le T_i \le 10^6).

Output

If the buildings cannot all be served, print impossible.

Otherwise print MM lines. Line ii holds the indices of the cranes raised onto building ii, 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.