#P2528. [SHOI2001] 排序工作量之新任务

[SHOI2001] 排序工作量之新任务

Description

Suppose we define the parameter of the ii-th item as AiA_i. Sorting means arranging A1,,AnA_1, \cdots ,A_n in ascending order. If i<ji < j and Ai>AjA_i > A_j, then (i,j)(i, j) is an “inversion pair.” The SORT company specializes in providing sorting services. Their pricing is based on the number of inversion pairs among the items to be sorted, called the “inversion count.”

Grant is a sorter at this company. He wants to know, among all sequences of nn items with distinct parameters, how many have inversion count tt, and to also provide one lexicographically smallest such sequence. “Smallest” means: for two sequences (A1,A2,,An)(A_1,A_2,\cdots ,A_n) and (B1,B2,,Bn)(B_1,B_2,\cdots ,B_n), if there exists 1in1 \le i \le n such that $(A_1,A_2,\cdots ,A_{i-1})=(B_1,B_2,\cdots ,B_{i-1})$ and Ai<BiA_i < B_i.

Input Format

Two integers nn and tt (1n201 \le n \le 20, 0tn(n1)20 \le t \le \dfrac{n\cdot (n-1)}{2}).

Output Format

  • The first line contains the number of sequences of nn distinct items whose inversion count is tt.
  • The second line is the requested sequence of item parameters. Assume the nn items are labeled 11 to nn.
4 3
6
1 4 3 2

Hint

Translated by ChatGPT 5