# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1128395 | pemguimn | Sprinklers (CEOI24_sprinklers) | C++17 | 48 ms | 2120 KiB |
#include <bits/stdc++.h>
#define pii pair<int, int>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, m, a[N], b[N];
string dir, fin;
bool check(int x){
dir = "";
int d = 0;
for(int i = 1; i <= n; i++){
if(d == m) {dir += 'L'; continue;}
if(b[d + 1] < a[i]){
dir += 'L';
while(d < m && b[d + 1] >= a[i] - x && b[d + 1] <= a[i]) d++;
} else{
dir += 'R';
while(d < m && b[d + 1] >= a[i] && b[d + 1] <= a[i] + x) d++;
}
}
return d == m;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#define task "sprinklers"
if(fopen(task ".inp", "r")){
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) cin >> b[i];
int lo = 0, hi = 1e9, ans = -1;
while(lo <= hi){
int mid = (lo + hi) / 2;
if(check(mid)) ans = mid, hi = mid - 1, fin = dir;
else lo = mid + 1;
}
cout << ans << '\n' << fin;
return 0;
}
Compilation message (stderr)
# | 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... |