#P10806. [CEOI 2024] 洒水器
[CEOI 2024] 洒水器
Problem Description
This problem is translated from CEOI 2024 Day 2 T3「Sprinklers」.
Vaclav has a beautiful garden, where he planted a row of flowers. Along this row, Vaclav also placed sprinklers to water the flowers.
The sprinkler positions are given by numbers . The flower positions are given by numbers . Both sequences are in non-decreasing order, that is:
- .
- .
Vaclav will soon leave to attend CEOI. He wants to make sure that all flowers will be watered properly while he is away. To do this, he can rotate each sprinkler individually to the left or to the right, and set their spray power. Since all sprinklers share the same water pipe, the spray range is the same for all of them.
If the spray power is and the -th sprinkler is rotated to the left, it will water all flowers at positions between and . Similarly, if the -th sprinkler is rotated to the right, it will water all flowers at positions between and . One sprinkler can water multiple flowers, and one flower can be watered by multiple sprinklers.
Your task is to decide whether it is possible to water all the flowers. If it is, you should find the smallest spray power that is sufficient, and a corresponding sprinkler configuration. If there are multiple valid configurations with the minimum spray power, output any one of them.
Input Format
The first line contains two integers and , separated by spaces. The second line contains integers , separated by spaces, representing the sprinkler positions. The third line contains integers , separated by spaces, representing the flower positions.
Output Format
If it is impossible to water all flowers, output the number .
If it is possible, the output should contain two lines. The first line outputs the number , the minimum spray power needed to water all flowers. In the second line, output a string of length , where is L if the -th sprinkler should be rotated to the left, otherwise it is R.
3 3
10 10 10
5 11 16
6
LLR
1 2
1000
1 2000
-1
Hint
Sample Explanation 1
Each flower is watered by at least one sprinkler. A spray power smaller than is impossible, because the flower at position is at distance from the nearest sprinkler.
Sample Explanation 2
No matter how the sprinklers are oriented, at most one flower can be watered at a time.
For all input data, it holds that:
- .
- .
- .
- .
- .
The detailed additional constraints and scores for subtasks are given in the table below.
| Subtask | Additional Constraints | Score |
|---|---|---|
| , where is an integer, and $s_{3i+1} = s_{3i+2} = s_{3i+3}\ (0 \leq i \leq x-1)$ (i.e., sprinklers are always placed in groups of three) | ||
| (i.e., for all testdata, there exists a sprinkler configuration such that a spray power of at most is sufficient to water all flowers) | ||
| No additional constraints |
Translated by ChatGPT 5