#K35067. Lexicographically Smallest Non-Increasing Array

    ID: 25449 Type: Default 1000ms 256MiB

Lexicographically Smallest Non-Increasing Array

Lexicographically Smallest Non-Increasing Array

You are given an array of integers and an integer ( k ) representing the number of swap operations allowed. Your task is to obtain the lexicographically smallest array among all arrays that are in non-increasing order (i.e. sorted in descending order) by performing exactly ( k ) swap operations. In this problem, an array ( A ) is said to be lexicographically smaller than an array ( B ) if there exists an index ( i ) such that ( A_j = B_j ) for all ( j < i ) and ( A_i < B_i ).

Note that if the array is already in non-increasing order, it remains unchanged regardless of the number of swaps allowed. Although the value of ( k ) is provided, the expected outcome is simply the array sorted in descending order.

For example:

  • For input array [1, 2, 3] with \( k = 0 \), the output is [3, 2, 1].
  • For input array [4, 3, 2, 1] with \( k = 1 \), the output is [4, 3, 2, 1].
  • For input array [3, 5, 2, 4, 1] with \( k = 3 \), the output is [5, 4, 3, 2, 1].

inputFormat

The first line contains two space-separated integers ( n ) and ( k ), where ( n ) is the number of elements in the array and ( k ) is the number of swap operations allowed. The second line contains ( n ) space-separated integers representing the array.

outputFormat

Output a single line containing the array sorted in non-increasing (descending) order. The numbers should be output as space-separated values.## sample

3 0
1 2 3
3 2 1

</p>