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);
vector<int> x(n+1);
x[0] = -1;
int j = 0;
for (int i = 0; i < n; i++) {
if (s[i] <= x[i])
x[i+1] = s[i]+k, d[i] = 'R';
else if (f[j] < s[i]) {
if (s[i]-f[j] > k)
return false;
x[i+1] = s[i], d[i] = 'L';
} else
x[i+1] = s[i]+k, d[i] = 'R';
while (j < m && f[j] <= x[i])
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;
}
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... |