Polynomial Round 2022 (Div. 1 + Div. 2, Rated, Prizes!)
H
Maximum Permutation
Codeforces
3500
原题
← G→
翻译中…

Ecrade bought a deck of cards numbered from $1$ to $n$. Let the value of a permutation $a$ of length $n$ be $\min\limits_{i = 1}^{n - k + 1}\ \sum\limits_{j = i}^{i + k - 1}a_j$.

翻译中…

Ecrade wants to find the most valuable one among all permutations of the cards. However, it seems a little difficult, so please help him!

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 2 \cdot 10^4$)  — the number of test cases. The description of test cases follows.

翻译中…

The only line of each test case contains two integers $n,k$ ($4 \leq k \lt n \leq 10^5$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^6$.

翻译中…

Output

翻译中…

For each test case, output the largest possible value in the first line. Then in the second line, print $n$ integers $a_1,a_2,\dots,a_n$ ($1 \le a_i \le n$, all $a_i$ are distinct)  — the elements of the permutation that has the largest value.

翻译中…

If there are multiple such permutations, output any of them.

翻译中…

Note

翻译中…

In the first test case, $[1,4,5,3,2]$ has a value of $13$. It can be shown that no permutations of length $5$ have a value greater than $13$ when $k = 4$.

翻译中…

In the second test case, $[4,2,5,7,8,3,1,6]$ has a value of $18$. It can be shown that no permutations of length $8$ have a value greater than $18$ when $k = 4$.

翻译中…

样例

Input #1
2
5 4
8 4
Output #1
13
1 4 5 3 2
18
4 2 5 7 8 3 1 6
InputCopy OutputCopy
题目信息
题号
1774H
时间限制
2 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。