#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 |
1 |
Correct |
33 ms |
8092 KB |
Output is correct |
2 |
Correct |
48 ms |
8296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
8300 KB |
Output is correct |
2 |
Correct |
48 ms |
8336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
6 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5068 KB |
Output is correct |
2 |
Correct |
5 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5080 KB |
Output is correct |
2 |
Correct |
6 ms |
5168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5068 KB |
Output is correct |
2 |
Correct |
5 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5068 KB |
Output is correct |
2 |
Correct |
5 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
7668 KB |
Output is correct |
2 |
Correct |
31 ms |
6936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
8000 KB |
Output is correct |
2 |
Correct |
25 ms |
7304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
7672 KB |
Output is correct |
2 |
Correct |
45 ms |
7864 KB |
Output is correct |