#include <bits/stdc++.h>
#define MAXN 100007
using namespace std;
string res;
int s[MAXN],f[MAXN],n,m;
bool check(int k){
res.clear();
int d=0;
for(int i=0;i<n;i++) {
if(d==m) {
res+='L';
continue;
}
if(f[d]<s[i]) {
if(f[d]<s[i]-k) return false;
res+='L';
while(d<m && f[d]<=s[i]) d++;
continue;
}
if(f[d]>=s[i]){
res+='R';
while(d<m && f[d]<=s[i]+k) d++;
}
}
if(d==m) return true;
return false;
}
int binarna(int l,int r)
{
if(l==r) return l;
int s=(l+r)/2;
if(check(s)) return binarna(l,s);
return binarna(s+1,r);
}
int main() {
cin>>n>>m;
for(int i=0;i<n;i++) cin>>s[i];
for(int i=0;i<m;i++) cin>>f[i];
int ans=binarna(1,1000000000);
if(!check(ans)) {
cout<<-1;
return 0;
}
cout<<ans<<endl<<res<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
21 ms |
1368 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
23 ms |
1664 KB |
Correct |
5 |
Correct |
24 ms |
1672 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
5 ms |
604 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
25 ms |
1620 KB |
Correct |
3 |
Correct |
5 ms |
560 KB |
Correct |
4 |
Correct |
67 ms |
3428 KB |
Correct |
5 |
Correct |
61 ms |
3412 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
60 ms |
3408 KB |
Correct |
9 |
Correct |
55 ms |
3408 KB |
Correct |
10 |
Correct |
55 ms |
3412 KB |
Correct |
11 |
Correct |
30 ms |
1876 KB |
Correct |
12 |
Correct |
42 ms |
2128 KB |
Correct |
13 |
Correct |
40 ms |
2392 KB |
Correct |
14 |
Correct |
43 ms |
2564 KB |
Correct |
15 |
Correct |
48 ms |
2696 KB |
Correct |
16 |
Correct |
39 ms |
2140 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Incorrect |
0 ms |
348 KB |
User solution is worse than jury's solution |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
30 ms |
1872 KB |
Correct |
3 |
Incorrect |
75 ms |
3304 KB |
User solution is worse than jury's solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
3 |
Correct |
21 ms |
1368 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
23 ms |
1664 KB |
Correct |
6 |
Correct |
24 ms |
1672 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
5 ms |
604 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Correct |
25 ms |
1620 KB |
Correct |
12 |
Correct |
5 ms |
560 KB |
Correct |
13 |
Correct |
67 ms |
3428 KB |
Correct |
14 |
Correct |
61 ms |
3412 KB |
Correct |
15 |
Correct |
0 ms |
348 KB |
Correct |
16 |
Correct |
0 ms |
348 KB |
Correct |
17 |
Correct |
60 ms |
3408 KB |
Correct |
18 |
Correct |
55 ms |
3408 KB |
Correct |
19 |
Correct |
55 ms |
3412 KB |
Correct |
20 |
Correct |
30 ms |
1876 KB |
Correct |
21 |
Correct |
42 ms |
2128 KB |
Correct |
22 |
Correct |
40 ms |
2392 KB |
Correct |
23 |
Correct |
43 ms |
2564 KB |
Correct |
24 |
Correct |
48 ms |
2696 KB |
Correct |
25 |
Correct |
39 ms |
2140 KB |
Correct |
26 |
Correct |
1 ms |
344 KB |
Correct |
27 |
Correct |
0 ms |
348 KB |
Correct |
28 |
Incorrect |
0 ms |
348 KB |
User solution is worse than jury's solution |
29 |
Halted |
0 ms |
0 KB |
- |