#P1323. Maximal Number after Digit Removal in a Generated Set

    ID: 14610 Type: Default 1000ms 256MiB

Maximal Number after Digit Removal in a Generated Set

Maximal Number after Digit Removal in a Generated Set

This problem is defined as follows. We start with a set whose elements are generated by the following rules:

\(1\) is in the set; and if \(P\) is in the set, then both \(2\times P+1\) and \(4\times P+5\) are also in the set.

Given an integer \(k\), extract the smallest \(k\) elements from the set (in increasing order), and concatenate their decimal representations (without any separators) to form a multi-digit number \(S\). Then, given another integer \(m\) (with \(m < |S|\)), remove exactly \(m\) digits from \(S\) (you may remove digits from any positions) so that the remaining number is as large as possible. Output both the original number \(S\) and the resulting number.

Note: It is guaranteed that you will never remove all digits of \(S\).

inputFormat

The input consists of two space‐separated integers \(k\) and \(m\) on one line:

  • \(k\): the number of smallest elements to extract from the generated set.
  • \(m\): the number of digits to remove from the concatenated number \(S\).

outputFormat

Output two numbers separated by a space:

  • The multi-digit number \(S\) obtained by concatenating the smallest \(k\) elements.
  • The maximum number that can be obtained by removing exactly \(m\) digits from \(S\).

sample

3 1
137 37