#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define en cout << '\n'
#define vi vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
const int N = 1e5+100;
int n, m, a[N], b[N];
void solve(){
cin >> n >> m;
vector<pii> v;
for(int i = 1; i <= n; ++i){
cin >> a[i];
v.pb({a[i], 1});
}
for(int i = 1; i <= m; ++i){
cin >> b[i];
v.pb({b[i], 0});
}
sort(all(v));
string soll;
int l = 0, r = 1e9, ans = -1;
while(l <= r){
int k = l+r>>1;
string sol = "";
bool ok = 1;
int last = -1e9, last_not_covered = 2e9;
for(int i = 0; i < n+m; ++i){
if(v[i].ss == 0){
if(last >= v[i].ff){
continue;
}
last_not_covered = min(last_not_covered, v[i].ff);
}else{
if(last_not_covered != 2e9 && last_not_covered < v[i].ff){
if(v[i].ff - last_not_covered > k){
ok = 0;
break;
}
last_not_covered = 2e9;
sol += 'L';
}else{
last_not_covered = 2e9;
last = v[i].ff + k;
sol += 'R';
}
}
}
if(last_not_covered != 2e9) ok = 0;
if(ok){
ans = k;
soll = sol;
r = k - 1;
}else{
l = k + 1;
}
}
cout << ans << '\n';
if(ans != -1){
cout << soll;
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
solve();
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:30:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int k = l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
344 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
10 ms |
2520 KB |
Correct |
3 |
Correct |
1 ms |
348 KB |
Correct |
4 |
Correct |
11 ms |
2648 KB |
Correct |
5 |
Correct |
11 ms |
2780 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
3 ms |
1116 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
22 ms |
2780 KB |
Correct |
3 |
Correct |
3 ms |
860 KB |
Correct |
4 |
Correct |
53 ms |
5120 KB |
Correct |
5 |
Correct |
50 ms |
5012 KB |
Correct |
6 |
Correct |
1 ms |
344 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
30 ms |
5088 KB |
Correct |
9 |
Correct |
28 ms |
4964 KB |
Correct |
10 |
Correct |
52 ms |
5156 KB |
Correct |
11 |
Correct |
16 ms |
3032 KB |
Correct |
12 |
Correct |
21 ms |
3288 KB |
Correct |
13 |
Correct |
33 ms |
4156 KB |
Correct |
14 |
Correct |
32 ms |
4308 KB |
Correct |
15 |
Correct |
34 ms |
4312 KB |
Correct |
16 |
Correct |
32 ms |
4052 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
344 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Incorrect |
1 ms |
344 KB |
User solution is worse than jury's solution |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
20 ms |
2956 KB |
Correct |
3 |
Incorrect |
56 ms |
5072 KB |
User solution is worse than jury's solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
344 KB |
Correct |
3 |
Correct |
10 ms |
2520 KB |
Correct |
4 |
Correct |
1 ms |
348 KB |
Correct |
5 |
Correct |
11 ms |
2648 KB |
Correct |
6 |
Correct |
11 ms |
2780 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
3 ms |
1116 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Correct |
22 ms |
2780 KB |
Correct |
12 |
Correct |
3 ms |
860 KB |
Correct |
13 |
Correct |
53 ms |
5120 KB |
Correct |
14 |
Correct |
50 ms |
5012 KB |
Correct |
15 |
Correct |
1 ms |
344 KB |
Correct |
16 |
Correct |
0 ms |
348 KB |
Correct |
17 |
Correct |
30 ms |
5088 KB |
Correct |
18 |
Correct |
28 ms |
4964 KB |
Correct |
19 |
Correct |
52 ms |
5156 KB |
Correct |
20 |
Correct |
16 ms |
3032 KB |
Correct |
21 |
Correct |
21 ms |
3288 KB |
Correct |
22 |
Correct |
33 ms |
4156 KB |
Correct |
23 |
Correct |
32 ms |
4308 KB |
Correct |
24 |
Correct |
34 ms |
4312 KB |
Correct |
25 |
Correct |
32 ms |
4052 KB |
Correct |
26 |
Correct |
0 ms |
348 KB |
Correct |
27 |
Correct |
0 ms |
348 KB |
Correct |
28 |
Incorrect |
1 ms |
344 KB |
User solution is worse than jury's solution |
29 |
Halted |
0 ms |
0 KB |
- |