#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> s(n), f(m);
for (int& e : s)
cin >> e;
for (int& e : f)
cin >> e;
vector<char> d(n);
auto check = [&](int k) {
d.assign(n, 0);
int x = -1;
int j = 0, pj = 0;
for (int i = 0; i < n; i++) {
if (s[i] <= x)
x = s[i]+k, d[i] = 'R';
else if (j < m && f[j] < s[i]) {
if (s[i]-f[j] > k)
return false;
x = s[i], d[i] = 'L';
if (i > 0 && d[i-1] == 'L' && s[i]-k <= f[pj]) {
x = s[i-1]+k;
d[i-1] = 'R';
} else
pj = j;
} else
x = s[i]+k, d[i] = 'R';
while (j < m && f[j] <= x)
j++;
}
return j == m;
};
if (!check(1e9)) {
cout << -1 << endl;
return 0;
}
int l = -1, r = 1e9;
while (r-l > 1) {
int m = (l+r)/2;
if (check(m))
r = m;
else
l = m;
}
check(r);
for (int i = 0; i < n; i++)
if (d[i] == 'L')
s[i] -= r;
sort(s.begin(), s.end());
int j = 0;
for (int e : s) {
if (j == m)
break;
assert(e <= f[j]);
while (j < m && f[j] <= e+r)
j++;
}
//assert(j == m);
cout << r << endl;
for (char c : d)
cout << c;
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
21 ms |
592 KB |
Correct |
3 |
Correct |
1 ms |
336 KB |
Correct |
4 |
Correct |
35 ms |
592 KB |
Correct |
5 |
Correct |
24 ms |
592 KB |
Correct |
6 |
Correct |
1 ms |
336 KB |
Correct |
7 |
Correct |
1 ms |
504 KB |
Correct |
8 |
Correct |
8 ms |
336 KB |
Correct |
9 |
Correct |
1 ms |
336 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
27 ms |
760 KB |
Correct |
3 |
Correct |
6 ms |
336 KB |
Correct |
4 |
Correct |
67 ms |
1208 KB |
Correct |
5 |
Correct |
73 ms |
1208 KB |
Correct |
6 |
Correct |
1 ms |
336 KB |
Correct |
7 |
Correct |
1 ms |
336 KB |
Correct |
8 |
Correct |
66 ms |
1352 KB |
Correct |
9 |
Correct |
59 ms |
1352 KB |
Correct |
10 |
Correct |
64 ms |
1208 KB |
Correct |
11 |
Correct |
36 ms |
848 KB |
Correct |
12 |
Correct |
40 ms |
848 KB |
Correct |
13 |
Correct |
47 ms |
1104 KB |
Correct |
14 |
Correct |
57 ms |
1104 KB |
Correct |
15 |
Correct |
59 ms |
1100 KB |
Correct |
16 |
Correct |
43 ms |
1096 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
1 ms |
336 KB |
Correct |
4 |
Correct |
1 ms |
336 KB |
Correct |
5 |
Correct |
1 ms |
336 KB |
Correct |
6 |
Correct |
1 ms |
336 KB |
Correct |
7 |
Correct |
1 ms |
336 KB |
Correct |
8 |
Correct |
1 ms |
336 KB |
Correct |
9 |
Correct |
1 ms |
336 KB |
Correct |
10 |
Correct |
1 ms |
336 KB |
Correct |
11 |
Correct |
1 ms |
336 KB |
Correct |
12 |
Correct |
1 ms |
336 KB |
Correct |
13 |
Correct |
1 ms |
336 KB |
Correct |
14 |
Correct |
1 ms |
336 KB |
Correct |
15 |
Correct |
1 ms |
508 KB |
Correct |
16 |
Correct |
1 ms |
336 KB |
Correct |
17 |
Correct |
1 ms |
336 KB |
Correct |
18 |
Correct |
1 ms |
336 KB |
Correct |
19 |
Correct |
1 ms |
336 KB |
Correct |
20 |
Correct |
1 ms |
336 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
31 ms |
868 KB |
Correct |
3 |
Correct |
83 ms |
1352 KB |
Correct |
4 |
Correct |
86 ms |
1352 KB |
Correct |
5 |
Correct |
83 ms |
1360 KB |
Correct |
6 |
Correct |
94 ms |
1208 KB |
Correct |
7 |
Correct |
87 ms |
1216 KB |
Correct |
8 |
Correct |
81 ms |
1360 KB |
Correct |
9 |
Correct |
88 ms |
1352 KB |
Correct |
10 |
Correct |
81 ms |
1356 KB |
Correct |
11 |
Correct |
86 ms |
1352 KB |
Correct |
12 |
Correct |
1 ms |
336 KB |
Correct |
13 |
Correct |
1 ms |
336 KB |
Correct |
14 |
Correct |
45 ms |
916 KB |
Correct |
15 |
Correct |
37 ms |
840 KB |
Correct |
16 |
Correct |
36 ms |
1016 KB |
Correct |
17 |
Correct |
33 ms |
1352 KB |
Correct |
18 |
Correct |
41 ms |
1352 KB |
Correct |
19 |
Correct |
47 ms |
1308 KB |
Correct |
20 |
Correct |
71 ms |
1352 KB |
Correct |
21 |
Correct |
70 ms |
1352 KB |
Correct |
22 |
Correct |
68 ms |
2616 KB |
Correct |
23 |
Incorrect |
76 ms |
2596 KB |
User solution is worse than jury's solution |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
21 ms |
592 KB |
Correct |
4 |
Correct |
1 ms |
336 KB |
Correct |
5 |
Correct |
35 ms |
592 KB |
Correct |
6 |
Correct |
24 ms |
592 KB |
Correct |
7 |
Correct |
1 ms |
336 KB |
Correct |
8 |
Correct |
1 ms |
504 KB |
Correct |
9 |
Correct |
8 ms |
336 KB |
Correct |
10 |
Correct |
1 ms |
336 KB |
Correct |
11 |
Correct |
27 ms |
760 KB |
Correct |
12 |
Correct |
6 ms |
336 KB |
Correct |
13 |
Correct |
67 ms |
1208 KB |
Correct |
14 |
Correct |
73 ms |
1208 KB |
Correct |
15 |
Correct |
1 ms |
336 KB |
Correct |
16 |
Correct |
1 ms |
336 KB |
Correct |
17 |
Correct |
66 ms |
1352 KB |
Correct |
18 |
Correct |
59 ms |
1352 KB |
Correct |
19 |
Correct |
64 ms |
1208 KB |
Correct |
20 |
Correct |
36 ms |
848 KB |
Correct |
21 |
Correct |
40 ms |
848 KB |
Correct |
22 |
Correct |
47 ms |
1104 KB |
Correct |
23 |
Correct |
57 ms |
1104 KB |
Correct |
24 |
Correct |
59 ms |
1100 KB |
Correct |
25 |
Correct |
43 ms |
1096 KB |
Correct |
26 |
Correct |
1 ms |
336 KB |
Correct |
27 |
Correct |
1 ms |
336 KB |
Correct |
28 |
Correct |
1 ms |
336 KB |
Correct |
29 |
Correct |
1 ms |
336 KB |
Correct |
30 |
Correct |
1 ms |
336 KB |
Correct |
31 |
Correct |
1 ms |
336 KB |
Correct |
32 |
Correct |
1 ms |
336 KB |
Correct |
33 |
Correct |
1 ms |
336 KB |
Correct |
34 |
Correct |
1 ms |
336 KB |
Correct |
35 |
Correct |
1 ms |
336 KB |
Correct |
36 |
Correct |
1 ms |
336 KB |
Correct |
37 |
Correct |
1 ms |
336 KB |
Correct |
38 |
Correct |
1 ms |
508 KB |
Correct |
39 |
Correct |
1 ms |
336 KB |
Correct |
40 |
Correct |
1 ms |
336 KB |
Correct |
41 |
Correct |
1 ms |
336 KB |
Correct |
42 |
Correct |
1 ms |
336 KB |
Correct |
43 |
Correct |
1 ms |
336 KB |
Correct |
44 |
Correct |
31 ms |
868 KB |
Correct |
45 |
Correct |
83 ms |
1352 KB |
Correct |
46 |
Correct |
86 ms |
1352 KB |
Correct |
47 |
Correct |
83 ms |
1360 KB |
Correct |
48 |
Correct |
94 ms |
1208 KB |
Correct |
49 |
Correct |
87 ms |
1216 KB |
Correct |
50 |
Correct |
81 ms |
1360 KB |
Correct |
51 |
Correct |
88 ms |
1352 KB |
Correct |
52 |
Correct |
81 ms |
1356 KB |
Correct |
53 |
Correct |
86 ms |
1352 KB |
Correct |
54 |
Correct |
1 ms |
336 KB |
Correct |
55 |
Correct |
1 ms |
336 KB |
Correct |
56 |
Correct |
45 ms |
916 KB |
Correct |
57 |
Correct |
37 ms |
840 KB |
Correct |
58 |
Correct |
36 ms |
1016 KB |
Correct |
59 |
Correct |
33 ms |
1352 KB |
Correct |
60 |
Correct |
41 ms |
1352 KB |
Correct |
61 |
Correct |
47 ms |
1308 KB |
Correct |
62 |
Correct |
71 ms |
1352 KB |
Correct |
63 |
Correct |
70 ms |
1352 KB |
Correct |
64 |
Correct |
68 ms |
2616 KB |
Correct |
65 |
Incorrect |
76 ms |
2596 KB |
User solution is worse than jury's solution |
66 |
Halted |
0 ms |
0 KB |
- |