fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define sl(n) scanf("%lld", &n)
  6. #define for1(i, stop) for(ll i = 1; i <= stop; ++i)
  7. #define pf printf
  8.  
  9. const ll sz = 1e5 + 10;
  10. ll a[sz], b[sz];
  11.  
  12. int main()
  13. {
  14. ll t; sl(t);
  15.  
  16. while(t--) {
  17. ll n, m;
  18. sl(n),sl(m);
  19.  
  20. for1(i, n) {
  21. sl(a[i]);
  22. }
  23.  
  24. for1(i, m) {
  25. sl(b[i]);
  26. }
  27.  
  28. sort(a+1, a+n+1);
  29. sort(b+1, b+m+1, greater<ll>());
  30.  
  31. ll ans = 0;
  32. for1(i, min(n, m)) {
  33. if(a[i] >= b[i]) break;
  34. ans += b[i]-a[i];
  35. }
  36.  
  37. pf("%lld\n", ans);
  38. }
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5620KB
stdin
2
3 4
10 70 20
50 60 1 5
3 1
10 70 20
50
stdout
80
40