#P10806. Sprinklers
Sprinklers
Sprinklers
Watslaw has a beautiful garden with a row of \(M\) flowers. In the same row, he has placed \(N\) sprinklers at positions \(s_1, s_2, \ldots, s_N\) (in non‐decreasing order). The flowers are located at positions \(f_1, f_2, \ldots, f_M\) (also in non‐decreasing order).
Watslaw is about to leave for CEOI, and he wants to ensure that every flower gets enough water while he is away. In order to water the flowers, he can individually rotate each sprinkler to either face left or right and set their spraying intensity. All sprinklers share the same water pump, and hence they all spray water to the same distance \(K\) (the intensity).
If the spraying intensity is \(K\), a sprinkler at position \(s_i\) when rotated left covers the interval \([s_i-K,\, s_i]\), and when rotated right covers the interval \([s_i,\, s_i+K]\). A single sprinkler may water several flowers and a flower may be watered by more than one sprinkler.
Your task is to decide whether it is possible to water all the flowers. If it is possible, you should determine the minimum spraying intensity \(K\) (an integer) that is sufficient, and output any valid configuration of orientations for the sprinklers achieving this intensity. If it is impossible to water all the flowers, output -1.
Note: All formulas are rendered in \(\LaTeX\) format.
inputFormat
The input consists of three lines:
- The first line contains two integers \(N\) and \(M\) (the number of sprinklers and flowers, respectively).
- The second line contains \(N\) non-decreasing integers \(s_1, s_2, \ldots, s_N\) representing the positions of the sprinklers.
- The third line contains \(M\) non-decreasing integers \(f_1, f_2, \ldots, f_M\) representing the positions of the flowers.
It is guaranteed that all numbers are separated by spaces.
outputFormat
If it is possible to water all the flowers, output two lines:
- The first line contains the minimum spraying intensity \(K\) (a non-negative integer).
- The second line contains a string of length \(N\). The \(i\)-th character must be either 'L' or 'R', indicating that the \(i\)-th sprinkler is rotated left or right respectively.
If it is impossible to water all the flowers, output a single line with the integer -1
.
sample
3 3
3 8 12
1 5 10
3
LLL
</p>