Hiker Safety

Hikers on markers along a route must take turns stepping forward so that neighbours stay within distance B and everyone keeps their personal space; output the lexicographically smallest order in which all reach the end, or impossible.

Hard8GreedySimulationImplementationNo attempts yetTime limit4sMemory limit512 MB

Problem

A hiking club runs a time trial along a single route. The route has PP marker points, marker ii sits did_i metres from the start, and d1=0d_1 = 0. The slow part of this sport is the pathfinding, so once a hiker knows where to go next, the walk itself takes no time at all.

KK hikers are on the route. Hiker ii stands on marker ViV_i and needs AiA_i metres of personal space. Two rules hold at every moment.

  • Two hikers that are neighbours on the route, meaning no other hiker stands between them, are at most BB metres apart.
  • Hiker ii keeps everyone else at least AiA_i metres away, so the distance between hiker ii and hiker jj is at least max(Ai,Aj)\max(A_i, A_j).

The hikers move one at a time. A single move takes one hiker from the marker they stand on to the next marker and finishes instantly, so nobody is ever between two markers. Both rules hold again after every move.

A hiker who reaches marker PP has finished the route and leaves it at once. From that moment the two rules ignore that hiker, so a move onto marker PP is always allowed. A hiker who stands on marker PP at the start has already finished and never moves.

Work out the order in which the hikers move so that all of them finish the route.

Input

  • One line with the integer BB (1B500001 \le B \le 50000), the largest distance allowed between two neighbouring hikers.
  • One line with the integer PP (3P10003 \le P \le 1000), the number of marker points.
  • One line with PP integers d1,d2,,dPd_1, d_2, \ldots, d_P (0=d1<d2<<dP1060 = d_1 < d_2 < \cdots < d_P \le 10^6), the distance of each marker from the start.
  • One line with the integer KK (2K10002 \le K \le 1000), the number of hikers.
  • KK lines, the ii-th of which holds two integers AiA_i and ViV_i (1Ai1061 \le A_i \le 10^6, 1ViP1 \le V_i \le P), the personal space and the current marker of hiker ii. The hikers are listed from the start of the route onwards, so V1<V2<<VKV_1 < V_2 < \cdots < V_K.

The starting arrangement obeys both rules. A hiker who starts on marker PP has already finished and is left out of that check.

Output

If the hikers cannot all reach marker PP without breaking a rule, print impossible.

Otherwise print the hiker numbers in the order they move, separated by single spaces, on one line. Every correct answer has the same length i=1K(PVi)\sum_{i=1}^{K} (P - V_i), so print the lexicographically smallest one. Compare two answers one position at a time; the answer with the smaller number at the first position where they differ comes first.