cswork / OAOpen practice workspace

AmazonOA #151

Find K-Level Permutation

Estimated MediumJudge-ready

Topics (AI-labelled)Bits & MathGreedy

Given N and an even K, construct a permutation of 1..N such that, among the sums of all contiguous subarrays of length K, the difference between the maximum and the minimum is at most 1. You may return any permutation that satisfies the condition. The full definition was recovered by cross-checking the Amazon source of the same problem with Codeforces 1927E.

Input

One line with two integers N K. Constraints added by this site: 2≤K≤N≤200000, and K is even.

Output

Output N integers representing a permutation that satisfies the condition. Any valid permutation is accepted; it need not match the order in the examples or the solution.

Example 1

Input:

7 4

Output:

1 7 3 5 2 6 4

Example notes

The fixed OAMaster example output is [1,7,3,5,2,6,4]; the sums of the four windows of length 4 are 16, 17, 16, 17.

Editorial

Loading solution…