Kratki
의견: 0
\(6^{th}\) round, February \(7^{th}\) 2015
All of you are probably very familiar with the problem of finding the longest monotone subsequence.
You probably think you know all about it. In order to convince us, solve the problem “opposite” to
finding the longest monotone subsequence.
For given \(N\) and \(K\), find the sequence that consists of numbers from 1 to \(N\) such that each of the
numbers in it appears exactly once and the length of its longest monotone subsequence (ascending or
descending) is exactly \(K\).
The first line of input contains the integers \(N\) and \(K\) (1 ⩽\(K\) ⩽\(N\) ⩽\(10^{6}\)), the length of the sequence
and the required length of the longest monotone subsequence.
If the required sequence doesn’t exist, outp\(ut -1\) in the first and only line.
If the required sequence exists, output the required sequence of \(N\) numbers in the first and only line.
Separate the numbers with a single space.
The required sequence (if it exists) is not necessarily unique, so you can output any valid sequence.
4 3
5 1
5 5output
output
1 4 2 3
-1
1 2 3 4 5Clarification of the first sample test: A sequence of length 4 with longest monotone subsequence of length
3 is (1, 4, 2, 3). The longest monotone sequence is (1, 2, 3).
평가 및 의견
Kratki
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Kratki