inline ll calc(ll x) { ll w = 0; for (int i = 0; i < n; ++i) w += llabs(a[i] + x); for (int i = 0; i < m; ++i) w += llabs(b[i] - x); return w + llabs(x); } intmain(void) { int i; sf(n), sf(m); for (i = 0; i < n; ++i) scanf("%lld", a + i); for (i = 0; i < m; ++i) scanf("%lld", b + i); ll l = -1e9 - 10, r = 1e9 + 10, midl, midr; while (l + 1 < r) { midl = (l + r) >> 1, midr = (midl + r) >> 1; if (calc(midl) <= calc(midr)) r = midr; else l = midl; } printf("%lld\n", min(calc(l), calc(r))); return0; }