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;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;
const int MAXN = 1e5 + 5;
int n, m;
int a[MAXN], b[MAXN];
bool check(int x){
int curr = 0;
REP(i, m){
if(curr >= n) return false;
while(abs(a[curr] - b[i]) > x && curr < n)
curr ++;
if(curr == n)
return false;
curr ++;
}
return true;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
REP(i, n)
cin >> a[i];
REP(i, m)
cin >> b[i];
sort(a, a + n);
sort(b, b + m);
if(n < m){
swap(a, b);
swap(n, m);
}
int lo = 0, hi = 1e9;
while(lo < hi){
int mid = (lo + hi) >> 1;
if(check(mid))
hi = mid;
else
lo = mid + 1;
}
cout << lo;
}
# | 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... |