#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;
// ll rightest = -1;
vi leftest(n);
while (i < n && j < m) {
if (abs(f[j] - s[i]) > k) return 0;
if (f[j] >= s[i]) {
leftest[i] = f[j] - s[i] <= k ? j : -1;
while (j < m && f[j] - s[i] <= k) j++;
ri[i] = 1;
// rightest = s[i] + k;
i++;
continue;
}
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;
// rightest = s[i - 1] + k;
} 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;
}
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 |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Correct |
2 |
Correct |
7 ms |
1880 KB |
Correct |
3 |
Correct |
0 ms |
344 KB |
Correct |
4 |
Correct |
7 ms |
2140 KB |
Correct |
5 |
Correct |
7 ms |
2188 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
472 KB |
Correct |
8 |
Correct |
2 ms |
604 KB |
Correct |
9 |
Correct |
1 ms |
348 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Incorrect |
10 ms |
2396 KB |
User solution is worse than jury's solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
3 |
Incorrect |
0 ms |
344 KB |
User solution is worse than jury's solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Incorrect |
9 ms |
2396 KB |
User solution is worse than jury's solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
348 KB |
Correct |
3 |
Correct |
7 ms |
1880 KB |
Correct |
4 |
Correct |
0 ms |
344 KB |
Correct |
5 |
Correct |
7 ms |
2140 KB |
Correct |
6 |
Correct |
7 ms |
2188 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
472 KB |
Correct |
9 |
Correct |
2 ms |
604 KB |
Correct |
10 |
Correct |
1 ms |
348 KB |
Correct |
11 |
Incorrect |
10 ms |
2396 KB |
User solution is worse than jury's solution |
12 |
Halted |
0 ms |
0 KB |
- |