#FT0000236. Số vòng sắp xếp nổi bọt II (Bubble Sort Rounds II)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 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 , determine the exact array after rounds of this procedure, even if exceeds the number of rounds required for sorting. Once sorted, later rounds do not change the array. If , the array remains unchanged.
Input
- The first line contains two integers : the array length and number of rounds.
- The second line contains exactly integers in their initial order.
Output
Print exactly integers on one line, from left to right, representing the array after rounds.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
5 2
3 2 4 1 4
Output
2 1 3 4 4
Explanation
The initial array is , and rounds are required.
- Round : scanning left to right swaps with , then with . The array becomes .
- Round : and are left unchanged, while and are swapped. The remaining pairs require no swap. The array becomes .
The result is not yet fully sorted, but exactly two rounds were requested, so print 2 1 3 4 4.