1772C. DifferentDifferences(Codeforces Round 839 (Div. 3))

C. Different Differences

time limit per test2 seconds

memory limit per test512 megabytes

inputstandard input

outputstandard output

An array aa consisting of kk integers is strictly increasing if a1<a2<⋯<aka1<a2<⋯<ak. For example, the arrays [1,3,5][1,3,5], [1,2,3,4][1,2,3,4], [3,5,6][3,5,6] are strictly increasing; the arrays [2,2][2,2], [3,7,5][3,7,5], [7,4,3][7,4,3], [1,2,2,3][1,2,2,3] are not.

For a strictly increasing array aa of kk elements, let's denote the characteristic as the number of different elements in the array [a2−a1,a3−a2,…,ak−ak−1][a2−a1,a3−a2,…,ak−ak−1]. For example, the characteristic of the array [1,3,4,7,8][1,3,4,7,8] is 33 since the array [2,1,3,1][2,1,3,1] contains 33 different elements: 22, 11 and 33.

You are given two integers kk and nn (k≤nk≤n). Construct an increasing array of kk integers from 11 to nn with maximum possible characteristic.

Input

The first line contains one integer tt (1≤t≤8191≤t≤819) — the number of test cases.

Each test case consists of one line containing two integers kk and nn (2≤k≤n≤402≤k≤n≤40).

Output

For each test case, print kk integers — the elements of the strictly increasing array aa with the maximum possible characteristic. If there are multiple answers, print any of them.

Example

input

Copy

75 94 123 33 44 44 68 11

output

Copy

1 3 4 7 8

2 4 7 12

1 2 3

1 3 4

1 2 3 4

2 4 5 6

1 2 3 5 6 7 8 11

题意就是说给你k和n,k是要求构造出的数组的长度,n是构造出的数组中最大的数不能超过n,题目要求构造出的数组满足

1,是严格的单调递增

2,数组中相邻两个数的差的值不相同的数量最多。比如k=5,n=9时,输出1 3 4 7 8,那么差值为

2 1 3 1,不同的值为3。

思路:我们可以采用贪心的策略,使得差值为1 2 3 4...,构造一个形如1 2 4 7 11..这样的数组,但是光这样构造难免会因为k的长度一直累加下去最大值会超过n,无法将k完全填充,而剩下来的数无法保证严格递增,那么该怎么办呢。

这时我们发现题目中数字在数组中位置的值是有一个上限的,也就是说每个位置都有一个最大的值,超过这个值就不能构造下去了。比如比如k=5,n=9时,可以得到这样的数组5 6 7 8 9,这样是满足严格递增,但是如果数组中第一个值为6,那么会构造出6 7 8 9 10,显然是非法的,也就是该数组第一位的值不能大于5,同理第二位的值不能大于6.,如果大于了,就直接把这个位置的值赋于最大值,因为此时最大的特征值已经构造完毕,后面随便怎么处理。

此时得到的约束条件能帮助我们构造出数组了。

代码如下。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值