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 ll long long
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 2e5+5;
const ll mod = 1e9 + 7;
const int base = 40;
ll n, m, k, t, a[N], b[N], c[N], tong, dp[N], lab[N];
long long ans;
vector<ll> adj[N];
pll p[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
bool ccw(pll x, pll y, pll z)
{
return x.fi * (y.se - z.se) + y.fi * (z.se - x.se) + z.fi * (x.se - y.se) >= 0;
}
ll C(ll u, ll v)
{
if(u > v)return 0;
return a[v] * b[u] % mod * b[v-u] % mod;
}
ll findp(ll u)
{
return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(ll u, ll v)
{
if(lab[u] > lab[v])swap(u, v);
lab[u] += lab[v];
lab[v] = u;
if(a[v] && a[u] && a[u] != a[v])ans = 1;
a[u] = max(a[v], a[u]);
}
bool check(ll x)
{
for(int i = 1, j = 1; i <= n; i ++)
{
while(j <= m && abs(a[i]-b[j]) > x)++j;
if(j > m)return false;
++j;
}
return true;
}
void sol()
{
cin >> n >> m;
if(n < m)
{
for(int i = 1; i <= n; i ++)cin >> a[i];
for(int i = 1; i <= m; i ++)cin >> b[i];
}
else
{
for(int i = 1; i <= n; i ++)cin >> b[i];
for(int i = 1; i <= m; i ++)cin >> a[i];
swap(n, m);
}
sort(a+1, a+1+n);
sort(b+1, b+1+m);
ll lf = 0, rt = 1e9, mid;
while(lf <= rt)
{
mid = (lf + rt) / 2;
if(check(mid))rt = mid - 1;
else lf = mid + 1;
}
cout << lf;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int test = 1;
//cin >> test;
while (test-- > 0)
sol();
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... |