Sprinklers
시간 제한2초메모리 제한1024 MB
직선 위에 정렬된 N개의 살수기와 M개의 꽃 위치가 주어질 때, 각 살수기의 방향과 모든 꽃을 덮는 최소 공통 분사 거리 K를 구한다.
문제
Václav has a beautiful flower garden consisting of flowers planted on a single line. On this line, Václav has also placed sprinklers to water his flowers.
The positions of the sprinklers are given by the numbers . The positions of the flowers are given by the numbers . Both are provided in non-decreasing order, that is:
Václav is leaving for CEOI soon. He would like to make sure that all of his flowers are properly watered while he is away. To do this, he turns each sprinkler individually to the left or to the right, and sets their spraying power — all sprinklers share the same water hose, and therefore spray the same distance.
If the spraying power is and the -th sprinkler is turned to the left, it will water all flowers with positions between and (inclusive). Similarly, if the -th sprinkler is turned to the right, it will water all flowers with positions between and (inclusive). A single sprinkler can water multiple flowers and a single flower can be watered by multiple sprinklers.
Your task is to decide whether it's possible to water all the flowers. If so, you should find the minimum sufficient spraying power, along with a corresponding configuration of sprinklers. If there exist multiple valid configurations with minimal spraying power, output any of them.
입력
The first line of input contains two integers: and , separated by a space. The second line contains space-separated integers — the positions of the sprinklers. The third line contains space-separated integers — the positions of the flowers.
출력
If it is not possible to water all the flowers, print the number .
If it is possible, the output should consist of two lines. On the first line, output the number – the minimum spraying power required to water all the flowers. On the second line, print a string of length , such that is L if the -th sprinkler should be turned to the left and R otherwise.
제한
- (for each such that )
- (for each such that )
- for all
- for all