A15606 | Maximum Permutation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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!
Ecrade wants to find the most valuable one among all permutations of the cards. However, it seems a little difficult, so please help him!
输入格式
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 < n \leq 10^5$ ).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^6$ .
The only line of each test case contains two integers $n,k$ ( $4 \leq k < n \leq 10^5$ ).
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^6$ .
输出格式
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.
If there are multiple such permutations, output any of them.
输入输出样例
输入 #1
2 5 4 8 4
输出 #1
13 1 3 4 5 2 18 1 8 2 7 3 6 4 5
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted