#P8397. Constructing a Musical Piece with Exact Good Subscores
Constructing a Musical Piece with Exact Good Subscores
Constructing a Musical Piece with Exact Good Subscores
You are given two integers \(m\) and \(k\). Your task is to construct a musical piece (i.e. a sequence of notes) satisfying the following requirements:
- Every note in the piece is an integer strictly less than \(m\).
- A subscore is defined as any non-empty contiguous subsequence of notes. A subsequence qualifies as a subscore if, after removing duplicates and sorting, every two adjacent numbers differ by exactly \(1\). For example, the following are valid subscores of the piece
(1, 2, 3, 4, 2)
:(3, 4, 2)
,(1, 2, 3, 4, 2)
, and(4)
. However,(1, 3)
is not, because after deduplication \(\{1,3\}\) the difference is not \(1\). - A subscore is considered good if all numbers in it are pairwise distinct.
- The constructed musical piece must contain exactly \(k\) good subscores (subscores with different starting or ending positions are counted as different).
Note: You are allowed to output any valid musical piece meeting the criteria. It is guaranteed that \(m \ge 1\) and \(k \ge 1\). One simple approach is to output a piece where all notes are equal to \(0\). In such a piece, only the single-note subscores are good. Hence, if you output a piece of length \(k\) with all notes equal to \(0\), there will be exactly \(k\) good subscores.
If a valid musical piece exists, output YES
followed by the description of the piece. Otherwise, output NO
.
inputFormat
The input consists of a single line containing two space-separated integers \(m\) and \(k\). \(m\) is the upper bound for the notes (all notes must be less than \(m\)), and \(k\) is the required number of good subscores.
outputFormat
If a valid musical piece can be constructed, output YES
on the first line. On the second line, output an integer \(n\) denoting the length of the musical piece. On the third line, output \(n\) space-separated integers representing the notes of the musical piece. Otherwise, output NO
.
sample
5 3
YES
3
0 0 0
</p>