CF1774H.Maximum Permutation

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ecrade bought a deck of cards numbered from 11 to nn. Let the value of a permutation aa of length nn be min⁡i=1n−k+1 ∑j=ii+k−1aj\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 购买了一副编号从 11 到 nn 的扑克牌。定义一个长度为 nn 的排列 aa 的价值为 min⁡i=1n−k+1 ∑j=ii+k−1aj\min\limits_{i = 1}^{n - k + 1}\ \sum\limits_{j = i}^{i + k - 1}a_j。

Ecrade 希望在所有卡片的排列中找出价值最大的那个。然而,这似乎有点困难,所以请帮帮他!

输入格式

The first line contains a single integer tt (1≤t≤2⋅1041 \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,kn,k (4≤k<n≤1054 \leq k \lt n \leq 10^5).

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

第一行包含一个整数 tt(1≤t≤2⋅1041 \leq t \leq 2 \cdot 10^4)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 kk(4≤k<n≤1054 \leq k \lt n \leq 10^5)。

保证所有测试用例的 nn 之和不超过 2⋅1062 \cdot 10^6。

输出格式

For each test case, output the largest possible value in the first line. Then in the second line, print nn integers a1,a2,…,ana_1,a_2,\dots,a_n (1≤ai≤n1 \le a_i \le n, all aia_i are distinct) — the elements of the permutation that has the largest value.

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

对于每个测试用例,在第一行输出可能的最大值。然后在第二行输出 nn 个整数 a1,a2,…,ana_1,a_2,\dots,a_n(其中 1≤ai≤n1 \le a_i \le n,且所有 aia_i 互不相同)——即达到该最大值的排列的各个元素。

如果存在多个满足条件的排列,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    5 4
    8 4

    输出#1

    13
    1 4 5 3 2
    18
    4 2 5 7 8 3 1 6

说明/提示

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

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

在第一个测试用例中,[1,4,5,3,2][1,4,5,3,2] 的值为 1313。可以证明:当 k=4k = 4 时,不存在长度为 55 的排列其值大于 1313。

在第二个测试用例中,[4,2,5,7,8,3,1,6][4,2,5,7,8,3,1,6] 的值为 1818。可以证明:当 k=4k = 4 时,不存在长度为 88 的排列其值大于 1818。

输入解题思路,AI测评打分。不知道怎么写?

首页