#P3584. Circle Food Satisfaction

    ID: 16837 Type: Default 1000ms 256MiB

Circle Food Satisfaction

Circle Food Satisfaction

There are n dishes arranged in a circle on a round table, where the i-th dish has ci calories. Between every two adjacent dishes sits one person (so there are n persons in total). Each person sits between two dishes and has two choices: they can either choose to eat the dish on their left or the dish on their right. If two persons choose the same dish, they share it equally and each gets half of its calories.

A person is dissatisfied if by changing his own choice (while all other persons keep their choices) his calorie intake strictly increases. Your task is to assign to each person a choice (left or right) so that no person is dissatisfied (i.e. no one can improve his calorie intake by switching).

The choices affect the sharing of dishes as follows. For a dish j:

  • If only one of the two adjacent persons chooses to eat dish j, that person gets cj calories.
  • If both persons choose dish j, each gets \(\frac{c_j}{2}\) calories.

For the person sitting between dish i and dish i+1 (indices taken modulo n), define his decision d[i] as:

  • L: he eats dish i.
  • R: he eats dish i+1.

The calorie intake of person i under an assignment depends on the decisions of his two neighbors:
If d[i]=L, then his intake is
\(A_i = \begin{cases} c_i, & \text{if } d[i-1]=L \\ \frac{c_i}{2}, & \text{if } d[i-1]=R \end{cases}\)
and if he were to switch to R his intake would be
\(B_i = \begin{cases} \frac{c_{i+1}}{2}, & \text{if } d[i+1]=L \\ c_{i+1}, & \text{if } d[i+1]=R \end{cases}\).

Similarly, if d[i]=R, his current intake is
\(A'_i = \begin{cases} \frac{c_{i+1}}{2}, & \text{if } d[i+1]=L \\ c_{i+1}, & \text{if } d[i+1]=R \end{cases}\)
and switching to L would yield
\(B'_i = \begin{cases} \frac{c_i}{2}, & \text{if } d[i-1]=R \\ c_i, & \text{if } d[i-1]=L \end{cases}\).

An assignment is valid if for every person i the chosen option gives an intake at least as high as that from switching. It can be shown that a valid assignment always exists. One such solution is given by the following construction:

For each person i (with 1‑based indexing), let the next index be i+1 (with dish n+1 interpreted as dish 1). Then assign \[ d[i] = \begin{cases} L, & \text{if } 2\,c_i \ge c_{i+1}, \\ R, & \text{if } 2\,c_i < c_{i+1}. \end{cases} \]

Explanation: When a person chooses L his intake will be either ci (if his left neighbor chooses L) or \(\frac{c_i}{2}\) (if his left neighbor chooses R). Likewise, if he chooses R, his intake is determined by the decision of his right neighbor. With the above rule the local conditions ensure that switching does not yield strictly higher calories.

You are to implement this assignment rule.

inputFormat

The first line contains an integer n (n ≥ 3) representing the number of dishes (and persons). The second line contains n space‐separated positive integers c1, c2, ..., cn, where ci represents the calorie value of the i-th dish. The indices are considered modulo n (i.e. dish n+1 is dish 1).

Note: It is guaranteed that a valid assignment exists.

outputFormat

Output a string of length n consisting only of characters 'L' and 'R'. The i-th character indicates the choice for the person sitting between dish i and dish i+1 ('L' means he eats dish i and 'R' means he eats dish i+1). The output must correspond to an assignment where no person can strictly improve his calorie intake by switching his choice.

sample

3
5 4 10
LRL

</p>