#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAX_N = 1e5 + 5;
ll s[MAX_N], f[MAX_N];
int ri[MAX_N];
int n, m;
bool Solve(int k) {
int i = 0, j = 0;
vi leftest(n);
while (i < n && j < m) {
if (f[j] >= s[i]) {
leftest[i] = -1;
while (j < m && f[j] - s[i] <= k) j++;
ri[i] = 1;
i++;
continue;
}
if (s[i] - f[j] > k) return 0;
ri[i] = 0;
if (i && leftest[i - 1] != -1 && s[i] - f[leftest[i - 1]] <= k) {
leftest[i] = leftest[i - 1];
while (j < m && f[j] - s[i - 1] <= k) j++;
ri[i - 1] = 1;
} else {
leftest[i] = j;
}
while (j < m && f[j] <= s[i] && s[i] - f[j] <= k) j++;
i++;
}
return j == m;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < m; i++) cin >> f[i];
int begin = 0, end = 1e9 + 1;
while (begin < end) {
int mid = (begin + end) >> 1;
if (Solve(mid)) end = mid;
else begin = mid + 1;
}
// int end;
// for (end = 0; end <= 8; end++) {
// if (Solve(end)) break;
// }
if (!Solve(end)) {
cout << -1 << '\n';
return 0;
}
cout << end << '\n';
for (int i = 0; i < n; i++) {
cout << (ri[i] ? 'R' : 'L');
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
6 ms |
1116 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
6 ms |
1252 KB |
Correct |
5 |
Correct |
6 ms |
1068 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
2 ms |
604 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
8 ms |
1116 KB |
Correct |
3 |
Correct |
2 ms |
604 KB |
Correct |
4 |
Correct |
23 ms |
2708 KB |
Correct |
5 |
Correct |
24 ms |
2772 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
13 ms |
2432 KB |
Correct |
9 |
Correct |
14 ms |
2512 KB |
Correct |
10 |
Correct |
18 ms |
2772 KB |
Correct |
11 |
Correct |
12 ms |
2004 KB |
Correct |
12 |
Correct |
12 ms |
1732 KB |
Correct |
13 |
Correct |
17 ms |
2516 KB |
Correct |
14 |
Correct |
20 ms |
2564 KB |
Correct |
15 |
Correct |
23 ms |
2516 KB |
Correct |
16 |
Correct |
16 ms |
2512 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Correct |
14 |
Correct |
0 ms |
348 KB |
Correct |
15 |
Correct |
0 ms |
348 KB |
Correct |
16 |
Correct |
0 ms |
348 KB |
Correct |
17 |
Correct |
0 ms |
348 KB |
Correct |
18 |
Correct |
0 ms |
348 KB |
Correct |
19 |
Correct |
0 ms |
480 KB |
Correct |
20 |
Correct |
1 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
9 ms |
1372 KB |
Correct |
3 |
Correct |
35 ms |
2816 KB |
Correct |
4 |
Correct |
35 ms |
2768 KB |
Correct |
5 |
Correct |
37 ms |
2768 KB |
Correct |
6 |
Correct |
33 ms |
2772 KB |
Correct |
7 |
Correct |
35 ms |
2780 KB |
Correct |
8 |
Correct |
34 ms |
2768 KB |
Correct |
9 |
Correct |
34 ms |
2752 KB |
Correct |
10 |
Correct |
34 ms |
2772 KB |
Correct |
11 |
Correct |
42 ms |
2792 KB |
Correct |
12 |
Correct |
0 ms |
348 KB |
Correct |
13 |
Correct |
0 ms |
348 KB |
Correct |
14 |
Correct |
12 ms |
2000 KB |
Correct |
15 |
Correct |
13 ms |
2140 KB |
Correct |
16 |
Correct |
16 ms |
2004 KB |
Correct |
17 |
Correct |
11 ms |
2752 KB |
Correct |
18 |
Correct |
13 ms |
2816 KB |
Correct |
19 |
Correct |
14 ms |
2772 KB |
Correct |
20 |
Correct |
28 ms |
2812 KB |
Correct |
21 |
Correct |
28 ms |
2768 KB |
Correct |
22 |
Correct |
25 ms |
2772 KB |
Correct |
23 |
Incorrect |
26 ms |
4052 KB |
User solution is worse than jury's solution |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
0 ms |
348 KB |
Correct |
3 |
Correct |
6 ms |
1116 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
6 ms |
1252 KB |
Correct |
6 |
Correct |
6 ms |
1068 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
2 ms |
604 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Correct |
8 ms |
1116 KB |
Correct |
12 |
Correct |
2 ms |
604 KB |
Correct |
13 |
Correct |
23 ms |
2708 KB |
Correct |
14 |
Correct |
24 ms |
2772 KB |
Correct |
15 |
Correct |
0 ms |
348 KB |
Correct |
16 |
Correct |
0 ms |
348 KB |
Correct |
17 |
Correct |
13 ms |
2432 KB |
Correct |
18 |
Correct |
14 ms |
2512 KB |
Correct |
19 |
Correct |
18 ms |
2772 KB |
Correct |
20 |
Correct |
12 ms |
2004 KB |
Correct |
21 |
Correct |
12 ms |
1732 KB |
Correct |
22 |
Correct |
17 ms |
2516 KB |
Correct |
23 |
Correct |
20 ms |
2564 KB |
Correct |
24 |
Correct |
23 ms |
2516 KB |
Correct |
25 |
Correct |
16 ms |
2512 KB |
Correct |
26 |
Correct |
0 ms |
348 KB |
Correct |
27 |
Correct |
0 ms |
348 KB |
Correct |
28 |
Correct |
0 ms |
348 KB |
Correct |
29 |
Correct |
0 ms |
348 KB |
Correct |
30 |
Correct |
0 ms |
348 KB |
Correct |
31 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Correct |
37 |
Correct |
0 ms |
348 KB |
Correct |
38 |
Correct |
0 ms |
348 KB |
Correct |
39 |
Correct |
0 ms |
348 KB |
Correct |
40 |
Correct |
0 ms |
348 KB |
Correct |
41 |
Correct |
0 ms |
348 KB |
Correct |
42 |
Correct |
0 ms |
480 KB |
Correct |
43 |
Correct |
1 ms |
348 KB |
Correct |
44 |
Correct |
9 ms |
1372 KB |
Correct |
45 |
Correct |
35 ms |
2816 KB |
Correct |
46 |
Correct |
35 ms |
2768 KB |
Correct |
47 |
Correct |
37 ms |
2768 KB |
Correct |
48 |
Correct |
33 ms |
2772 KB |
Correct |
49 |
Correct |
35 ms |
2780 KB |
Correct |
50 |
Correct |
34 ms |
2768 KB |
Correct |
51 |
Correct |
34 ms |
2752 KB |
Correct |
52 |
Correct |
34 ms |
2772 KB |
Correct |
53 |
Correct |
42 ms |
2792 KB |
Correct |
54 |
Correct |
0 ms |
348 KB |
Correct |
55 |
Correct |
0 ms |
348 KB |
Correct |
56 |
Correct |
12 ms |
2000 KB |
Correct |
57 |
Correct |
13 ms |
2140 KB |
Correct |
58 |
Correct |
16 ms |
2004 KB |
Correct |
59 |
Correct |
11 ms |
2752 KB |
Correct |
60 |
Correct |
13 ms |
2816 KB |
Correct |
61 |
Correct |
14 ms |
2772 KB |
Correct |
62 |
Correct |
28 ms |
2812 KB |
Correct |
63 |
Correct |
28 ms |
2768 KB |
Correct |
64 |
Correct |
25 ms |
2772 KB |
Correct |
65 |
Incorrect |
26 ms |
4052 KB |
User solution is worse than jury's solution |
66 |
Halted |
0 ms |
0 KB |
- |