PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000236. Số vòng sắp xếp nổi bọt II (Bubble Sort Rounds II)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số vòng sắp xếp nổi bọt II (Bubble Sort Rounds II)

Bubble Sort Rounds II

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

An array of nn integers is processed by bubble sort. During each round, the algorithm scans adjacent pairs from left to right. Whenever the left element is greater than the right element, the elements are swapped immediately; equal elements are not swapped.

Given a number of rounds kk, determine the exact array after kk rounds of this procedure, even if kk exceeds the number of rounds required for sorting. Once sorted, later rounds do not change the array. If k=0k=0, the array remains unchanged.

Input

  • The first line contains two integers n,kn,k: the array length and number of rounds.
  • The second line contains exactly nn integers x1,x2,…,xnx_1,x_2,\ldots,x_n in their initial order.

Output

Print exactly nn integers on one line, from left to right, representing the array after kk rounds.

Subtasks

  • Subtask 1 (20 points): 1≤n≤501\le n\le 50; 0≤k≤1090\le k\le 10^9; 1≤xi≤10000000001\le x_i\le 1000000000 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 0≤k≤1090\le k\le 10^9; 1≤xi≤10000000001\le x_i\le 1000000000 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 0≤k≤1090\le k\le 10^9; 1≤xi≤10000000001\le x_i\le 1000000000 for every 1≤i≤n1\le i\le n.

Examples

Input

5 2
3 2 4 1 4

Output

2 1 3 4 4

Explanation

The initial array is [3,2,4,1,4][3,2,4,1,4], and k=2k=2 rounds are required.

  • Round 11: scanning left to right swaps 33 with 22, then 44 with 11. The array becomes [2,3,1,4,4][2,3,1,4,4].
  • Round 22: 22 and 33 are left unchanged, while 33 and 11 are swapped. The remaining pairs require no swap. The array becomes [2,1,3,4,4][2,1,3,4,4].

The result is not yet fully sorted, but exactly two rounds were requested, so print 2 1 3 4 4.