CF BUDDY
← Problems·

1965B · Missing Subsequence Sum

1800 · bitmasks, constructive algorithms, greedy

Problem: You are given two integers nn and kk. Find a sequence aa of non-negative integers of size at most 2525 such that the following conditions hold.

  • There is no subsequence of aa with a sum of kk.
  • For all 1vn1 \le v \le n where vkv \ne k, there is a subsequence of aa with a sum of vv.

A sequence bb is a subsequence of aa if bb can be obtained from aa by the deletion of several (possibly, zero or all) elements, without changing the order of the remaining elements. For example, [5,2,3][5, 2, 3] is a subsequence of [1,5,7,8,2,4,3][1, 5, 7, 8, 2, 4, 3].

It can be shown that under the given constraints, a solution always exists.

Input Format: The first line of the input contains a single integer tt (1t10001 \le t \le 1000) — the number of test cases. The description of the test cases follows.

Each test case consists of a single line containing two integers nn and kk (2n1062 \le n \le 10^6, 1kn1 \le k \le n) — the parameters described above.

It is guaranteed that the sum of nn over all test cases does not exceed 10710^7.

Output Format: The first line of output for each test case should contain a single integer mm (1m251 \le m \le 25) — the size of your chosen sequence.

The second line of output for each test case should contain mm integers aia_i (0ai1090 \le a_i \le 10^9) — the elements of your chosen sequence.

If there are multiple solutions, print any.

Note: In the first example, we just need a subsequence that adds up to 11, but not one that adds up to 22. So the array a=[1]a=[1] suffices.

In the second example, all elements are greater than k=1k=1, so no subsequence adds up to 11. Every other integer between 11 and nn is present in the array, so there is a subsequence of size 11 adding up to each of those numbers.

Sample Cases

Case 1

Input

5
2 2
6 1
8 8
9 3
10 7

Output

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

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback