fork(1) download
  1. def optimal_game_cost(t, test_cases):
  2. results = []
  3. for n, k, a, b in test_cases:
  4. a.sort()
  5. b.sort(reverse=True)
  6. total = 0
  7. for i in range(n):
  8. total += abs(a[i] - b[i])
  9. results.append(total)
  10. return results
  11.  
  12. def main():
  13. t = int(input())
  14. test_cases = []
  15. for _ in range(t):
  16. n, k = map(int, input().split())
  17. a = list(map(int, input().split()))
  18. b = list(map(int, input().split()))
  19. test_cases.append((n, k, a, b))
  20. for res in optimal_game_cost(t, test_cases):
  21. print(res)
  22.  
  23. main()
  24.  
Success #stdin #stdout 0.07s 13980KB
stdin
5
2 1
1 7
3 5
3 2
1 5 3
6 2 4
5 4
1 16 10 10 16
3 2 2 15 15
4 1
23 1 18 4
19 2 10 3
10 10
4 3 2 100 4 1 2 4 5 5
1 200 4 5 6 1 10 2 3 4
stdout
8
9
54
60
320