Codeforces Round #839 (Div. 3)——C. Different Differences

215 阅读1分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第25天,点击查看活动详情

Codeforces Round #839 (Div. 3)——C. Different Differences

Problem - C - Codeforces

An array aa consisting of kk integers is strictly increasing if a1<a2<⋯<aka1<a2<⋯<ak. For example, the arrays 1,3,5, 1,2,3,4, 3,5,6 are strictly increasing; the arrays 2,2, 3,7,5, 7,4,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. For example, the characteristic of the array 1,3,4,7,8 is 33 since the array 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

7
5 9
4 12
3 3
3 4
4 4
4 6
8 11

output

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

问题解析

题目是说让你用1到n中k个不同的数升序排序,使得ai-a(i-1)得到的不同的数尽量的多。

可以知道,k个数的数组最多可以得到k-1个不同的ai-a(i-1),分别是1、2、……、k-1。

我们直接从1开始创建数组,逐步增大差值,注意得到的数不能超过n。

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>//#pragma GCC optimize(2)
//#pragma GCC optimize(3)#define endl '\n'
//#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 2e5 + 50, MOD = 998244353;
​
int a[N];
void solve()
{
    int n, k;
    cin >> k >> n;
    if (n == k)
    {
        for (int i = 1; i <= n; i++)cout << i << " ";
        cout << endl;
        return;
    }
    int cnt = 1;
    a[1] = 1;
    for (int i = 2; i <= k; i++)
    {
        if (a[i - 1] + cnt <= n - (k - i))
        {
            a[i] = a[i - 1] + cnt;
            cnt++;
        }
        else
        {
            cnt = 1;
            a[i] = a[i - 1] + 1;
        }
    }
    for(int i=1;i<=k;i++)cout << a[i] << " ";
    cout << endl;
}
​
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}