fork(1) download
  1. t = int(input())
  2.  
  3. while t >= 1:
  4. t -= 1
  5.  
  6. n, m = map(int, input().split())
  7. a = [0]*n; b =[0]*m
  8.  
  9. inp = input().split()
  10. for i in range(0, n):
  11. a[i] = int(inp[i])
  12.  
  13. inp = input().split()
  14. for i in range(0, m):
  15. b[i] = int(inp[i])
  16.  
  17. a.sort(); b.sort(reverse=True)
  18.  
  19. ans = 0
  20. for i in range(0, min(n,m)):
  21. if a[i] >= b[i]:
  22. break
  23. ans += b[i]-a[i]
  24.  
  25. print(ans)
  26.  
Success #stdin #stdout 0.02s 9268KB
stdin
2
3 4
10 70 20
50 60 1 5
3 1
10 70 20
50
stdout
80
40