Editorial
The analysis uses the notation , which means the remainder of dividing the number by . For example, .
If we number the letters in the alphabet from to (i.e., '', '', , '') and create a new array , where corresponds to the number of the letter , then the addition described in the condition is . Now our task is to make the array lexicographically minimal for a certain permutation .
It can be noticed that . This means that each can be replaced by .
Let's create a count array of the array , i.e., an array such that is the number of occurrences of the number in the array . Since the sequence in which the elements of the array are placed does not matter, we will work with their quantity.
Let's choose such for that is minimal. After that, we will use this and remove it from the count array. We will do the same for .
Thus, we always try to minimize the prefix of the array, which guarantees a lexicographically minimal array.
Problem Author: | Oleksandr Tymkovich |
Problem Prepared by: | Oleksandr Tymkovich |
Editorial by: | Oleksandr Tymkovich |