fork(1) download
  1. def calculate_game_value(t, test_cases):
  2. results = []
  3. for n, k, a, b in test_cases:
  4. a.sort()
  5. b.sort(reverse=True)
  6. diff = [abs(a[i] - b[i]) for i in range(n)]
  7. results.append(sum(diff))
  8. return results
  9.  
  10. def main():
  11. t = int(input())
  12. test_cases = []
  13. for _ in range(t):
  14. n, k = map(int, input().split())
  15. a = list(map(int, input().split()))
  16. b = list(map(int, input().split()))
  17. test_cases.append((n, k, a, b))
  18. answers = calculate_game_value(t, test_cases)
  19. for ans in answers:
  20. print(ans)
  21.  
  22. main()
  23.  
Success #stdin #stdout 0.11s 13984KB
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