#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a), end(a)
using ll = long long;
using vi = vector<int>;
using ar2 = array<int,2>;
const int mxN = (int)1e5+10;
const int INF = (int)2e9+10;
int n, m;
ar2 p[mxN];
string ans;
int f[mxN], s[mxN], dp[mxN];
bool chk(int d){
int j = 1, k = 1, l = 1;
for(int i = 1; i <= n; i++){
if(f[dp[i-1]+1]<s[i]-d) return 0;
while(j<=m and f[j]<=s[i]+d) j++;
while(k<=m and f[k]<=s[i]) k++;
while(l<=m and i>1 and f[l]<=s[i-1]+d) l++;
if(f[dp[i-1]+1]>=s[i]) dp[i]=j-1, p[i]={1,1};
else dp[i]=k-1, p[i]={1,0};
if(i>1 and f[dp[i-2]+1]>=s[i]-d)
if(dp[i]<l) dp[i]=l-1, p[i]={2,0};
}
return dp[n]==m;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> s[i], ans+='L';
for(int i = 1; i <= m; i++) cin >> f[i]; f[m+1]=INF;
int l = 0, r = (int)1e9;
while(l<r){
int mid = (l+r)/2;
if(chk(mid)) r=mid;
else l=mid+1;
}
if(!chk(l)){cout<<-1<<"\n";return 0;}
cout << l << "\n";
for(int i = n; i; i--){
if(p[i][0]==2) ans[i-1]='L',ans[i-2]='R', i--;
else ans[i-1]="LR"[p[i][1]];
}
cout << ans << "\n";
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:35:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
35 | for(int i = 1; i <= m; i++) cin >> f[i]; f[m+1]=INF;
| ^~~
Main.cpp:35:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
35 | for(int i = 1; i <= m; i++) cin >> f[i]; f[m+1]=INF;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
8 ms |
1372 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
9 ms |
1628 KB |
Correct |
5 |
Correct |
9 ms |
1624 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
1 ms |
348 KB |
Correct |
8 |
Correct |
2 ms |
600 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
10 ms |
1624 KB |
Correct |
3 |
Correct |
4 ms |
604 KB |
Correct |
4 |
Correct |
40 ms |
4580 KB |
Correct |
5 |
Correct |
44 ms |
4444 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
22 ms |
4616 KB |
Correct |
9 |
Correct |
25 ms |
4440 KB |
Correct |
10 |
Correct |
39 ms |
4432 KB |
Correct |
11 |
Correct |
17 ms |
3216 KB |
Correct |
12 |
Correct |
22 ms |
2652 KB |
Correct |
13 |
Correct |
36 ms |
3572 KB |
Correct |
14 |
Correct |
37 ms |
3636 KB |
Correct |
15 |
Correct |
37 ms |
3920 KB |
Correct |
16 |
Correct |
33 ms |
3416 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
1 ms |
348 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
600 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Correct |
0 ms |
348 KB |
Correct |
12 |
Correct |
0 ms |
348 KB |
Correct |
13 |
Correct |
0 ms |
348 KB |
Correct |
14 |
Correct |
0 ms |
348 KB |
Correct |
15 |
Correct |
0 ms |
348 KB |
Correct |
16 |
Correct |
0 ms |
344 KB |
Correct |
17 |
Correct |
0 ms |
348 KB |
Correct |
18 |
Correct |
0 ms |
348 KB |
Correct |
19 |
Correct |
0 ms |
344 KB |
Correct |
20 |
Correct |
0 ms |
348 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
15 ms |
1880 KB |
Correct |
3 |
Correct |
68 ms |
4444 KB |
Correct |
4 |
Correct |
68 ms |
4444 KB |
Correct |
5 |
Correct |
67 ms |
4560 KB |
Correct |
6 |
Correct |
70 ms |
4552 KB |
Correct |
7 |
Correct |
68 ms |
4440 KB |
Correct |
8 |
Correct |
72 ms |
4696 KB |
Correct |
9 |
Correct |
73 ms |
4444 KB |
Correct |
10 |
Correct |
73 ms |
4444 KB |
Correct |
11 |
Correct |
69 ms |
4440 KB |
Correct |
12 |
Correct |
0 ms |
344 KB |
Correct |
13 |
Correct |
0 ms |
348 KB |
Correct |
14 |
Correct |
17 ms |
3228 KB |
Correct |
15 |
Correct |
18 ms |
3164 KB |
Correct |
16 |
Correct |
18 ms |
3164 KB |
Correct |
17 |
Correct |
20 ms |
3160 KB |
Correct |
18 |
Correct |
21 ms |
3396 KB |
Correct |
19 |
Correct |
29 ms |
3676 KB |
Correct |
20 |
Correct |
66 ms |
4176 KB |
Correct |
21 |
Correct |
65 ms |
4176 KB |
Correct |
22 |
Correct |
64 ms |
3960 KB |
Correct |
23 |
Correct |
68 ms |
3928 KB |
Correct |
24 |
Correct |
57 ms |
3676 KB |
Correct |
25 |
Correct |
59 ms |
3676 KB |
Correct |
26 |
Correct |
19 ms |
2832 KB |
Correct |
27 |
Correct |
25 ms |
1880 KB |
Correct |
28 |
Correct |
50 ms |
3420 KB |
Correct |
29 |
Correct |
47 ms |
3416 KB |
Correct |
30 |
Correct |
49 ms |
3500 KB |
Correct |
31 |
Correct |
32 ms |
3420 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
8 ms |
1372 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
9 ms |
1628 KB |
Correct |
6 |
Correct |
9 ms |
1624 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
1 ms |
348 KB |
Correct |
9 |
Correct |
2 ms |
600 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Correct |
10 ms |
1624 KB |
Correct |
12 |
Correct |
4 ms |
604 KB |
Correct |
13 |
Correct |
40 ms |
4580 KB |
Correct |
14 |
Correct |
44 ms |
4444 KB |
Correct |
15 |
Correct |
0 ms |
348 KB |
Correct |
16 |
Correct |
0 ms |
348 KB |
Correct |
17 |
Correct |
22 ms |
4616 KB |
Correct |
18 |
Correct |
25 ms |
4440 KB |
Correct |
19 |
Correct |
39 ms |
4432 KB |
Correct |
20 |
Correct |
17 ms |
3216 KB |
Correct |
21 |
Correct |
22 ms |
2652 KB |
Correct |
22 |
Correct |
36 ms |
3572 KB |
Correct |
23 |
Correct |
37 ms |
3636 KB |
Correct |
24 |
Correct |
37 ms |
3920 KB |
Correct |
25 |
Correct |
33 ms |
3416 KB |
Correct |
26 |
Correct |
0 ms |
348 KB |
Correct |
27 |
Correct |
0 ms |
348 KB |
Correct |
28 |
Correct |
1 ms |
348 KB |
Correct |
29 |
Correct |
0 ms |
348 KB |
Correct |
30 |
Correct |
0 ms |
348 KB |
Correct |
31 |
Correct |
0 ms |
600 KB |
Correct |
32 |
Correct |
0 ms |
348 KB |
Correct |
33 |
Correct |
0 ms |
348 KB |
Correct |
34 |
Correct |
0 ms |
348 KB |
Correct |
35 |
Correct |
0 ms |
348 KB |
Correct |
36 |
Correct |
0 ms |
348 KB |
Correct |
37 |
Correct |
0 ms |
348 KB |
Correct |
38 |
Correct |
0 ms |
348 KB |
Correct |
39 |
Correct |
0 ms |
344 KB |
Correct |
40 |
Correct |
0 ms |
348 KB |
Correct |
41 |
Correct |
0 ms |
348 KB |
Correct |
42 |
Correct |
0 ms |
344 KB |
Correct |
43 |
Correct |
0 ms |
348 KB |
Correct |
44 |
Correct |
15 ms |
1880 KB |
Correct |
45 |
Correct |
68 ms |
4444 KB |
Correct |
46 |
Correct |
68 ms |
4444 KB |
Correct |
47 |
Correct |
67 ms |
4560 KB |
Correct |
48 |
Correct |
70 ms |
4552 KB |
Correct |
49 |
Correct |
68 ms |
4440 KB |
Correct |
50 |
Correct |
72 ms |
4696 KB |
Correct |
51 |
Correct |
73 ms |
4444 KB |
Correct |
52 |
Correct |
73 ms |
4444 KB |
Correct |
53 |
Correct |
69 ms |
4440 KB |
Correct |
54 |
Correct |
0 ms |
344 KB |
Correct |
55 |
Correct |
0 ms |
348 KB |
Correct |
56 |
Correct |
17 ms |
3228 KB |
Correct |
57 |
Correct |
18 ms |
3164 KB |
Correct |
58 |
Correct |
18 ms |
3164 KB |
Correct |
59 |
Correct |
20 ms |
3160 KB |
Correct |
60 |
Correct |
21 ms |
3396 KB |
Correct |
61 |
Correct |
29 ms |
3676 KB |
Correct |
62 |
Correct |
66 ms |
4176 KB |
Correct |
63 |
Correct |
65 ms |
4176 KB |
Correct |
64 |
Correct |
64 ms |
3960 KB |
Correct |
65 |
Correct |
68 ms |
3928 KB |
Correct |
66 |
Correct |
57 ms |
3676 KB |
Correct |
67 |
Correct |
59 ms |
3676 KB |
Correct |
68 |
Correct |
19 ms |
2832 KB |
Correct |
69 |
Correct |
25 ms |
1880 KB |
Correct |
70 |
Correct |
50 ms |
3420 KB |
Correct |
71 |
Correct |
47 ms |
3416 KB |
Correct |
72 |
Correct |
49 ms |
3500 KB |
Correct |
73 |
Correct |
32 ms |
3420 KB |
Correct |
74 |
Correct |
11 ms |
1880 KB |
Correct |
75 |
Correct |
61 ms |
4504 KB |
Correct |
76 |
Correct |
73 ms |
4444 KB |
Correct |
77 |
Correct |
0 ms |
344 KB |
Correct |
78 |
Correct |
19 ms |
4440 KB |
Correct |
79 |
Correct |
42 ms |
4568 KB |
Correct |
80 |
Correct |
24 ms |
4444 KB |
Correct |
81 |
Correct |
17 ms |
3164 KB |
Correct |
82 |
Correct |
18 ms |
3164 KB |
Correct |
83 |
Correct |
18 ms |
3276 KB |
Correct |
84 |
Correct |
9 ms |
1112 KB |
Correct |
85 |
Correct |
50 ms |
3676 KB |
Correct |
86 |
Correct |
55 ms |
3904 KB |
Correct |
87 |
Correct |
34 ms |
3520 KB |
Correct |
88 |
Correct |
15 ms |
1816 KB |
Correct |
89 |
Correct |
9 ms |
1628 KB |
Correct |