Skip to content

Commit e66725e

Browse files
committed
CT_399
1 parent 45f4a3c commit e66725e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package B1
2+
3+
fun main() {
4+
val (N, K) = readLine()!!.split(" ").map { it.toInt() }
5+
val A = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
6+
7+
print(if (bubbleSort(A, K)) A.joinToString(" ") else -1)
8+
}
9+
10+
fun bubbleSort(A: MutableList<Int>, K: Int): Boolean {
11+
12+
var cnt = 0
13+
14+
for (i in A.size - 1 downTo 0) {
15+
for (j in 0 until i) {
16+
if (A[j] > A[j + 1]) {
17+
A[j] = A[j + 1].also { A[j + 1] = A[j] }
18+
if (++cnt >= K) return true
19+
}
20+
}
21+
}
22+
23+
return false
24+
}

0 commit comments

Comments
 (0)