// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using str = string;
template<class T> using V = vector<T>;
// template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
using vs = V<str>;
using vi = V<int>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M; cin >> N >> M;
vi A(N); for(auto& x : A) cin >> x;
vi B(M); for(auto& x : B) cin >> x;
set<int> has(begin(A), end(A));
{
vi C; for(auto& x : B) if (!has.count(x)) C.pb(x);
B = C;
}
// if (A[0] > B.front() && A[0] < B.back()) {
// cout << -1 << nl;
// exit(0-0);
// }
// if (A[0] > B.front()) cout << A[0] - B.front() << nl << "L" << nl;
// else cout << B.back() - A[0] << nl << "R" << nl;
// exit(0-0);
auto chk = [&](int k) {
str ans(N, 'L');
int i = 0, j = 0;
while(i < M) {
// find the min j s.t. you match this flower with this sprinkler
if (j == N) break;
while(j < N && abs(B[i] - A[j]) > k) j++;
if (j == N) break;
int bnd = -1;
if (A[j] < B[i]) bnd = A[j] + k, ans[j] = 'R';
else bnd = A[j], ans[j] = 'L';
// cout << j << " " << ans[j] << endl;
// cout << i << endl;
j++;
while(i < M && B[i] <= bnd) i++;
}
if (i != M) return str("-1");
return ans;
};
int lo = 0, hi = 1e9 + 10;
while(lo < hi) {
int mid = (lo + hi) / 2;
// cout << mid << endl;
if (chk(mid) != "-1") hi = mid;
else lo = mid + 1;
}
str ans = chk(lo);
if (ans != "-1") {
cout << lo << nl;
// assert(lo == max(abs(A.front() - B.front()), abs(A.front() - B.back())));
}
cout << ans << nl;
exit(0-0);
}
// Breathe In, Breathe Out
# | 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... |