#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")
// PBDS Template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <class T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
//using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
// Preset
const int maxn = 200000;
const int INF = 2e9;
const long long int LINF = 1e18;
const long long int mod = 1e9 + 7;
const long long int mod2 = 998244353;
const double e = 2.71828;
const double PI = acos(-1);
const double eps = 1e-10;
#define pb push_back
#define ll long long
//#define int long long
#define ull unsigned long long
#define ld double
#define all(x) x.begin(), x.end()
typedef pair<char,char> pc;
typedef pair<double,double> pdb;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<pi,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef pair<char,int> pci;
typedef pair<int,char> pic;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
int dr[4] = {0,1,0,-1}, dc[4] = {1,0,-1,0};
void solve() {
int n,m;
cin >> n >> m;
pi p[n+m+5];
for (int i=1; i<=n; i++) {
cin >> p[i].first;
p[i].second = 0;
}
for (int i=n+1; i<=n+m; i++) {
cin >> p[i].first;
p[i].second = 1;
}
sort(p+1,p+n+m+1);
// for (int i=1; i<=n+m; i++) cout << p[i].first << ' ' << p[i].second << '\n';
int l = 0, r = 1e9, ans = INF;
string res = "";
while (l<=r) {
int mid = l + (r-l)/2;
// cout << "mid = " << mid << '\n';
stack<int> st;
int far = 0;
string cfg = "";
for (int i=1; i<=n+m; i++) {
int cur = p[i].first;
// cout << i << ' ' << cur << ' ' << far << '\n';
// stack<int> temp = st;
// cout << "isi stack =";
// while (!temp.empty()) {
// cout << ' ' << temp.top();
// temp.pop();
// }
// cout << '\n';
if (p[i].second == 0) {
if (!st.empty()) {
while (!st.empty()) {
int top = st.top();
if (p[top].first+mid >= cur) st.pop();
else break;
}
cfg.pb('L');
}
else {
far = max(far, cur+mid);
cfg.pb('R');
}
}
else {
if (far < cur) st.push(i);
}
}
if (st.empty()) {
ans = min(ans, mid);
res = cfg;
r = mid-1;
}
else l = mid+1;
}
if (ans == INF) cout << -1 << '\n';
else {
cout << ans << '\n';
cout << res << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// precompute();
// FFT::init_fft();
int tc = 1;
// cin >> tc;
// getchar();
// int idx = 1;
while (tc--) solve();
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... |