#C3070. Transform Array and Find Minimum

    ID: 46457 Type: Default 1000ms 256MiB

Transform Array and Find Minimum

Transform Array and Find Minimum

You are given an array of n integers and an integer k. Your task is to perform k operations on the array. In each operation, you must:

  • Find the maximum element in the array.
  • Remove one occurrence of this maximum element from the array.
  • Calculate the sum of its digits. In mathematical notation, for a number \(x\) with digits \(d_1, d_2, \dots, d_m\), the digit sum is \(S(x) = \sum_{i=1}^{m} d_i\).
  • Insert the digit sum back into the array.

After performing exactly k such operations, output the smallest element present in the array. Note that if k is zero, no operations are performed and you should simply return the minimum element from the original array.

This problem tests your ability to simulate operations and manipulate arrays efficiently.

inputFormat

The input is given via stdin and consists of two lines:

  1. 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 operations to perform.
  2. The second line contains n space-separated integers representing the array.

outputFormat

Output a single integer via stdout: the smallest number in the array after performing the k operations.

## sample
5 3
58 23 77 99 31
13