#K846. K-Distance Permutation Validation

    ID: 36455 Type: Default 1000ms 256MiB

K-Distance Permutation Validation

K-Distance Permutation Validation

Given a permutation \(P\) of length \(n\) and an integer \(k\), the permutation is said to satisfy the k-distance condition if for every index \(i\) with \(1 \le i \le n-k\), the following inequality holds:

\( P_i < P_{i+k} \)

All indices are 1-indexed. In other words, for every valid pair of positions that are \(k\) apart, the element at the earlier position must be strictly less than the element at the later position.

Your task is to check whether the given permutation meets this condition. If it does, print the permutation as is; otherwise, print \(-1\).

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  • The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the size of the permutation and \(k\) is the distance to check.
  • The second line contains \(n\) space-separated integers denoting the permutation \(P\).

outputFormat

Output to standard output (stdout) a single line:

  • If the permutation satisfies the condition \(P_i < P_{i+k}\) for all valid \(i\), output the original permutation as space-separated integers.
  • If the condition is violated at least once, output \(-1\).
## sample
5 2
1 3 2 5 4
1 3 2 5 4