#P15748. [JAG 2024 Summer Camp #3] Halfway Through the Book
[JAG 2024 Summer Camp #3] Halfway Through the Book
题目描述
A book titled "Immense Catalog of Permutation Compilation" is published by JAG Publisher. This book is extremely lengthy, with a total of pages. Each page contains one of the non-empty subsequences (not necessarily contiguous) of a permutation of length (i.e., a rearrangement of ). Each subsequence appears exactly once in lexicographical order. In other words, on the page , you'll find the -th lexicographically smallest subsequence of among all non-empty subsequences.
You've tried to read the entire book but gave up. However, you want to impress your friends by claiming that you read half of it, so you need to find the sequence on the exact middle page, which is page . Your task is to determine this sequence.
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} & N \\ & P_1 \ P_2 \ \ldots \ P_N \end{aligned} $$The first line contains an integer , where represents the length of permutation . is between and . The second line contains integers () which represent the permutation .
输出格式
On the first line, print , which represents the length of the sequence on page . On the second line, print integers , which represent the subsequence on page .
3
2 1 3
2
2 1
6
3 6 2 1 5 4
4
3 6 1 5