| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 72 | 14 | 14 | 25.926% |
Václav has a beautiful flower garden consisting of $M$ flowers planted on a single line. On this line, Václav has also placed $N$ sprinklers to water his flowers.
The positions of the sprinklers are given by the numbers $s_{1},\ldots,s_{N}$. The positions of the flowers are given by the numbers $f_{1},\ldots,f_{M}$. 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 $K$ and the $i$-th sprinkler is turned to the left, it will water all flowers with positions between $s_{i} - K$ and $s_{i}$ (inclusive). Similarly, if the $j$-th sprinkler is turned to the right, it will water all flowers with positions between $s_{j}$ and $s_{j} + K$ (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: $N$ and $M$, separated by a space. The second line contains $N$ space-separated integers $s_{1},\ldots,s_{N}$ — the positions of the sprinklers. The third line contains $M$ space-separated integers $f_{1},\ldots,f_{M}$ — the positions of the flowers.
If it is not possible to water all the flowers, print the number $-1$.
If it is possible, the output should consist of two lines. On the first line, output the number $K$ – the minimum spraying power required to water all the flowers. On the second line, print a string $c$ of length $N$, such that $c_i$ is L if the $i$-th sprinkler should be turned to the left and R otherwise.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 3 | $N = 1$ |
| 2 | 6 | $N = 3x$ for some integer $x$, $s_{3i+1}=s_{3i+2}=s_{3i+3}$ for each $i$ such that $0 \leq i \leq x-1$ (i.e. sprinklers are always placed in groups of three) |
| 3 | 17 | $N \leq 10, M \leq 1\,000$ |
| 4 | 27 | $K \leq 8$ (i.e., in all testcases there exists a configuration of sprinklers such that a spraying power of at most 8 is sufficient to water all of the flowers) |
| 5 | 47 | no additional constraints |
3 3 10 10 10 5 11 16
6 LLR
The given solution is valid — each flower is watered by at least one sprinkler. A spraying power lower than 6 is not possible, because the flower at location 16 is 6 units away from the closest sprinkler.
1 2 1000 1 2000
-1
At most one flower can be watered at one time regardless of the orientation of the only sprinkler.