This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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', pj = j;
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
x = s[i]+k, d[i] = 'R', pj = j;
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |