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 <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 1e5 + 10;
int n, m;
vector<ll> L, R;
bool check(ll x){
int cnt = 0;
for(int i = 0; i < m; i ++){
if(cnt >= n){
return true;
}
if(llabs(R[i] - L[cnt]) > x){
continue;
}
cnt ++;
}
return (cnt >= n);
}
int main(int argc, const char * argv[]) {
ios_base::sync_with_stdio(false);
// ifstream cin("in.txt");
cin >> n >> m;
ll num;
for(int i = 0; i < n; i ++){
cin >> num;
L.push_back(num);
}
for(int i = 0; i < m; i ++){
cin >> num;
R.push_back(num);
}
if(n > m){
swap(L, R);
}
n = (int)L.size();
m = (int)R.size();
sort(L.begin(), L.end());
sort(R.begin(), R.end());
ll levo = 0, desno = (1LL << 40LL);
// for(int i = 0; i < n; i ++){
// cout << L[i] << " ";
// }
// cout << endl;
// for(int i =0 ; i < m; i++){
// cout << R[i] << " ";
// }
// cout<<endl;
// cout << check(4) << endl;
ll ret = -1;
while(levo <= desno){
ll mid = levo + ((desno - levo) / 2LL);
if(check(mid)){
desno = mid -1;
ret = mid;
}
else{
levo = mid +1;
}
}
cout << ret << endl;
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... |