#K10766. Transforming Numbers with Limited Operations
Transforming Numbers with Limited Operations
Transforming Numbers with Limited Operations
Lina chooses a positive integer \(n\) and Tom is given exactly \(k\) operations to try to transform \(n\) into a number that is strictly greater than \(n\). In each operation, Tom must select one digit in \(n\) that exactly matches one of the allowed digits provided in a list and change it. The transformation is considered successful if Tom can perform exactly \(k\) operations and thus obtain a new number, which, due to the allowed changes, is guaranteed to be greater than the original \(n\).
Your task is to determine, given the number \(n\), the number of operations \(k\), and a list of allowed digits, whether it is possible for Tom to carry out exactly \(k\) such operations. If it is possible, print Yes
; otherwise, print No
.
Note: Each operation must modify a digit whose value exactly matches one of the allowed digits. The order in which operations are applied follows the order of the allowed digits list, and once a digit is modified in an operation, it cannot be used again for another operation.
inputFormat
The input consists of three lines:
- An integer \(n\) representing the original number.
- An integer \(k\) representing the number of operations Tom must perform.
- A space-separated list of allowed digits.
You may assume that \(n\) is a positive integer and the allowed digits are single digit numbers (0-9).
outputFormat
Output a single line containing Yes
if Tom can perform exactly \(k\) operations, transforming \(n\) into a strictly greater number, or No
otherwise.
54321
3
5 4 3
Yes