#P5868. [SEERC 2018] Min Max Convert
[SEERC 2018] Min Max Convert
Description
is an array with elements. You can perform the following two operations on this array:
- Choose an index interval . Let the maximum value among the elements in this interval be , and replace all elements in this interval with .
- Choose an index interval . Let the minimum value among the elements in this interval be , and replace all elements in this interval with .
Compute a sequence of operations that transforms array into another given array (also with elements). The number of operations in the sequence must be less than or equal to .
Input Format
The first line contains an integer .
The second line contains an array with elements.
The third line contains another array with elements.
Output Format
If there is no solution, output . Otherwise, output an integer in the first line, representing the minimum number of operations needed to transform array into . In the next lines, each line contains one character (representing the type of operation, m means the minimum-value operation is used, and M means the maximum-value operation is used) and an interval , describing each operation. If there are multiple solutions, output any one of them.
5
1 5 5 3 4
1 1 4 4 4
3
m 1 2
M 4 5
m 3 5
5
1 2 3 4 4
2 2 2 2 5
-1
Hint
- .
- All elements in arrays and are integers in the interval .
Translated by ChatGPT 5
京公网安备 11011102002149号