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;
long long int s[n];
long long int f[m];
for(int i = 0; i < n; i++){
cin >> s[i];
}
for(int i = 0; i < m; i++){
cin >> f[i];
}
long long int ans = 1e18;
long long int INF = 1e18;
int br1[n];
for(int k = 0; k < (1 << n); k++){
int br[n];
for(int j = 0; j < n; j++){
br[j] = 0;
}
int k1 = k;
int brojac = 0;
while(k1 > 0){
if(k1 % 2 == 1){
br[brojac]++;
}
brojac++;
k1 = k1 / 2;
}
long long int res = 0;
for(int i = 0; i < m; i++){
long long int mini = 1e18;
for(int j = 0; j < n; j++){
if(br[j] == 0){
if(s[j] <= f[i]){
mini = min(mini, f[i] - s[j]);
}
}else{
if(s[j] >= f[i]){
mini = min(mini, s[j] - f[i]);
}
}
}
res = max(res, mini);
}
if(res < ans){
ans = min(ans, res);
for(int j = 0; j < n; j++){
br1[j] = br[j];
}
}
}
if(ans == INF){
cout << -1;
}else{
cout << ans <<endl;
for(int i = 0; i < n; i++){
if(br1[i] == 0){
cout << "R";
}else{
cout << "L";
}
}
}
}
# | 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... |