#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
int main() {
    cin.tie(0)->sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> s(n), f(m);
    for (int &i : s)
        cin >> i;
    for (int &i : f)
        cin >> i;
    string o;
    int lo = 0, hi = 1e9, ans = -1;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        string c;
        int l = 0;
        for (int x : s) {
            if (l == m) {
                c.push_back('L');
                continue;
            }
            if (f[l] < x) {
                c.push_back('L');
                while (l < m && f[l] >= x - mid && f[l] <= x)
                    l++;
            } else {
                c.push_back('R');
                while (l < m && f[l] <= x + mid)
                    l++;
            }
        }
        if (l == m)
            ans = mid, o = c, hi = mid - 1;
        else
            lo = mid + 1;
    }
    if (ans == -1)
        cout << ans << '\n';
    else
        cout << ans << '\n' << o << '\n';
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |