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;
long long n, m, mini, maxi = 1000000010, medi, l[100000], r[100000];
bool can(long long u){
long long c = 0, p = 0;
if(n == m){
for(int i = 0; i < n; i++){
if(abs(l[i]-r[i]) > u) return false;
}
return true;
} else if(n < m){
for(int i = 0; i < m; i++){
if(abs(l[c]-r[i]) <= u){
c++;
p++;
if(c == n) break;
}
}
if(p == n) return true;
return false;
} else {
for(int i = 0; i < n; i++){
if(abs(r[c]-l[i]) <= u){
c++;
p++;
if(c == m) break;
}
}
if(p == m) return true;
return false;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> l[i];
for(int i = 0; i < m; i++) cin >> r[i];
sort(l, l+n);
sort(r, r+m);
while(mini < maxi){
medi = mini+(maxi-mini)/2;
if(can(medi)) maxi = medi;
else mini = medi+1;
}
cout << mini;
}
# | 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... |
# | 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... |