K-Regular Array

시간 제한2초메모리 제한2048 MB

요약
길이 k인 모든 부분 배열이 1부터 k까지를 모두 포함하도록 길이 n 배열을 만들고 원소 합을 최대로 한다.
난이도

보통10점 중 4점

유형
그리디, 배열, 수학, 구현
정답자
아직 제출이 없습니다

문제

An array aa of size nn is considered kk-regular if every subarray of aa of size kk contains all integers from 11 to kk, inclusive.

For example, a=\[2,1,3,2]a = \[2, 1, 3, 2] is 33-regular, because its two subarrays of size 33 are \[2,1,3]\[2, 1, 3] and \[1,3,2]\[1, 3, 2], each of which contains all integers from 11 to 33. On the other hand, a=\[1,2,3,4]a = \[1, 2, 3, 4] is not 33-regular because the subarray \[2,3,4]\[2, 3, 4] of size k=3k=3 does not contain 11.

Your task is to find a kk-regular array aa of size nn such that the sum of its elements is maximized.

입력

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) --- 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 (1≤k≤n≤2⋅1051 \le k \le n \le 2\cdot 10^5) --- the desired size of the array aa, and the parameter kk described above.

It is guaranteed that the sum of nn across all test cases is at most 2⋅1052\cdot 10^5.

출력

For each test case, output a single line containing nn integers a_1,a_2,⋯a_na\_1, a\_2, \cdots a\_n --- a kk-regular array aa of size nn with maximal sum.

If there are multiple solutions, you may print any.

힌트

In the first sample case, the array a=\[3,1,2,3]a = \[3, 1, 2, 3] is 33-regular because its two subarrays of size 33 are \[3,1,2]\[3, 1, 2] and \[1,2,3]\[1, 2, 3], each of which contains all integers from 11 to 33. The sum of this array is 3+1+2+3=93 + 1 + 2 + 3 = 9, which we can show is maximal for this nn and kk.

In the second sample case, each subarray of size 11 must contain 11, and therefore, the array must consist only of ones.

예제1

  1. 예제 1

    입력
    4
    4 3
    5 1
    3 2
    1 1
    
    예상 출력
    3 1 2 3
    1 1 1 1 1 
    2 1 2 
    1