#P2215. Lexicographically Minimal Increasing Subsequence

    ID: 15494 Type: Default 1000ms 256MiB

Lexicographically Minimal Increasing Subsequence

Lexicographically Minimal Increasing Subsequence

Given a sequence \( S = \{a_1, a_2, a_3, \dots, a_n\} \), a subsequence \( P = \{a_{x_1}, a_{x_2}, a_{x_3}, \dots, a_{x_m}\} \) is called an increasing subsequence if it satisfies both:

  • \( x_1 < x_2 < \dots < x_m \)
  • \( a_{x_1} < a_{x_2} < \dots < a_{x_m} \)

If there are several increasing subsequences of a given length, we wish to choose the one that is lexicographically smallest in terms of indices, i.e., the one whose first index is as small as possible; if there is a tie, compare the second index, and so on.

You are given the sequence \( S \) and several queries. For the \( i\)-th query, output the lexicographically smallest increasing subsequence of length \( L_i \). If no such subsequence exists, print Impossible.

inputFormat

The input consists of:

  1. The first line contains two integers \( n \) and \( q \) separated by a space, where \( n \) is the length of the sequence and \( q \) is the number of queries.
  2. The second line contains \( n \) integers representing the sequence \( S \): \( a_1, a_2, \dots, a_n \).
  3. Each of the following \( q \) lines contains a single integer \( L_i \) representing the required length of the subsequence.

outputFormat

For each query, output a single line. If there exists an increasing subsequence of length \( L_i \), print its elements (the chosen numbers from \( S \)) separated by spaces. Otherwise, print Impossible.

sample

5 3
1 2 3 4 5
3
5
6
1 2 3

1 2 3 4 5 Impossible

</p>