80pts啊啊啊
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
struct Node {
ll l;
int id;
bool operator <(const Node &T) const {
return l < T.l;
}
};
Node t[maxn];
ll a[maxn], b[maxn], r[maxn];
ll n, m, rmax, ans = 1e16;
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x * 10) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int main() {
n = read(), m = read();
for (int i = 1; i <= n; i++) a[i] = read();
b[0] = -1e16;
b[m + 1] = 1e16;
for (int i = 1; i <= m; i++) b[i] = read();
sort(b + 1, b + m + 1);
for (int i = 1; i <= n; i++) {
t[i].l = a[i] - b[upper_bound(b + 1, b + m + 1, a[i]) - b - 1];
t[i].id = i;
r[i] = b[upper_bound(b + 1, b + m + 1, a[i]) - b] - a[i];
}
sort(t + 1, t + n + 1);
for (int i = n; i >= 1; i--) {
ans = min(ans, min(t[i].l * 2 + rmax, rmax * 2 + t[i].l));
rmax = max(r[t[i].id], rmax);
}
printf("%lld\n", ans);
return 0;
}
这是本蒟蒻的代码,求调,必关!!!