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>
#define eb emplace_back
#define printv(a, b) {\
bool ps = false;\
for(auto pv : a){\
if(ps) b << ' '; ps = true;\
b << pv;\
}\
b << "\n";\
}
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
using namespace std;
int n, m;
vector<int> a, b;
int check(int k){
int now = 0;
int ans = 0;
for(int i = 0; i < n; i++){
while(now < m && b[now] < a[i] - k) now++;
if(now < m && abs(b[now] - a[i]) <= k){
ans++;
now++;
}
}
//cerr << "check " << k << " " << ans << "\n";
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
a.resize(n);
b.resize(m);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
lsort(a);
lsort(b);
int l = 0, r = 1000000000;
while(l < r){
int mid = (l + r) / 2;
if(check(mid) == min(n, m)) r = mid;
else l = mid + 1;
}
cout << l << "\n";
return 0;
}
# | 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... |