#include #include #include #include #define LL long long using namespace std; const int MAXN = 100050; int a[MAXN], b[MAXN], n, m, c[MAXN]; LL calc(int pos) { LL ans = 0; int t = 1; for (int i = pos; i <= n; ++ i) { if (t <= m && a[i] >= b[t]) ans += a[i] - b[t], ++ t; } return ans; } void work() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++ i) scanf("%d", a + i); for (int i = 1; i <= m; ++ i) scanf("%d", b + i); sort(a+1, a+1+n); sort(b+1, b+1+m); c[0] = 0; for (int i = 1; i <= n; ++ i) { int la = c[i-1]; while (la + 1 <= m && a[i] >= b[la + 1]) ++ la; c[i] = la; } LL ans = 0; int L = 0, R = n; while (L + 10 < R) { int lm = (2 * L + R) / 3, rm = (2 * R + L) / 3; if (calc(lm) < calc(rm)) L = lm; else R = rm; } for (int i = L; i <= R; ++ i) ans = max(ans, calc(i)); cout<= 1 && c[t-1] >= (n - (t-1) + 1)) -- t; /* int t1 = n + 1, t2 = 0; while (t2 + 1 <= m && t1 - 1 >= 1 && a[t1 - 1] >= b[t2+1]) ++ t2, -- t1; */ /* LL ans = 0; for (int i = n; i >= t; -- i) ans += a[i]; for (int j = 1; j <= (n - t + 1); ++ j) ans -= b[j]; cout<