#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=1e9+7,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,w,h,l;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int F[mxn+10],S[mxn+10],mid,di[mxn+10];
bool check(){
set<int>have;
for(int i=1;i<=m;i++)have.insert(F[i]);
for(int i=1;i<=n;i++){
if(have.empty())return 1;
int mn=(*have.begin());
if(mn<S[i]-mid)return 0;
//forced cases
if(mn>=S[i])di[i]=1;
else if((S[i]-mid)<=mn&&(S[i+1]-mid)>mn)di[i]=0;
else{
auto it=have.upper_bound(S[i]);
//if no flower are in between LR
if(it==have.end()||(*it)>=S[i+1])di[i]=0;
else di[i]=1;
}
if(di[i]==0){
while(have.size()&&(*have.begin())>=(S[i]-mid)&&(*have.begin())<=S[i])have.erase(have.begin());
}
else{
auto it=have.lb(S[i]);
while(it!=have.end()&&(*it)<=S[i]+mid)it=have.erase(it);
}
}
if(have.size())return 0;
return 1;
}
int32_t main(){
fastio
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>S[i];
S[n+1]=inf;
for(int i=1;i<=m;i++)cin>>F[i];
int l=0,r=1e9,ans=inf;
/*
while(l<=r){
mid=l+(r-l)/2;
if(check())r=mid-1,ans=min(ans,mid);
else l=mid+1;
}*/
int change=0;
for(mid=0;mid<=8;mid++){
int x=check();
if(x)ans=min(ans,mid);
change|=check();
if(change!=x)assert(0);
}
if(ans==inf)return (cout<<-1),0;
cout<<ans<<'\n';
mid=ans;
check();
for(int i=1;i<=n;i++)cout<<((di[i])?'R':'L');
}
/*
*/
Compilation message (stderr)
Main.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
Main.cpp:38:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
38 | void setIO(string name){
| ^
Main.cpp:44:12: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
44 | bool check(){
| ^
Main.cpp:71:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
71 | int32_t main(){
| ^
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |