CF1793B.Fedya and Array
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For his birthday recently Fedya was given an array a of n integers arranged in a circle, For each pair of neighboring numbers ( a1 and a2 , a2 and a3 , … , an−1 and an , an and a1 ) the absolute difference between them is equal to 1 .
Let's call a local maximum an element, which is greater than both of its neighboring elements. Also call a local minimum an element, which is less than both of its neighboring elements. Note, that elements a1 and an are neighboring elements.
Unfortunately, Fedya lost an array, but he remembered in it the sum of local maximums x and the sum of local minimums y .
Given x and y , help Fedya find any matching array of minimum length.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤1000 ). Description of the test cases follows.
Each line of each test case contain two integers x and y ( −109≤y<x≤109 ) — the sum of local maximums and the sum of local minimums, respectively.
输出格式
For each test case, in the first line print one integer n — the minimum length of matching arrays.
In the second line print n integers a1,a2,…,an ( −109⩽ai⩽109 ) — the array elements such that the the absolute difference between each pair of neighboring is equal to 1 .
If there are multiple solutions, print any of them.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输入输出样例
输入#1
4 3 -2 4 -4 2 -1 5 -3
输出#1
10 0 1 2 1 0 -1 0 -1 0 1 16 -2 -1 -2 -1 0 1 2 3 4 5 4 3 2 1 0 -1 6 1 0 -1 0 1 0 16 2 3 2 1 0 -1 0 -1 0 -1 0 1 2 1 0 1
说明/提示
In the first test case, the local maximums are the numbers at 3,7 and 10 positions, and the local minimums are the numbers at 1,6 and 8 positions. x=a3+a7+a10=2+0+1=3 , y=a1+a6+a8=0+(−1)+(−1)=−2 .
In the second test case, the local maximums are the numbers at 2 and 10 positions, and the local minimums are the numbers at 1 and 3 positions. x=a2+a10=−1+5=4 , y=a1+a3=−2+(−2)=−4 .
In the third test case, the local maximums are the numbers at 1 and 5 positions, and the local minimums are the numbers at 3 and 6 positions.