fork download
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. int t = scanner.nextInt();
  8.  
  9. for (int testCase = 0; testCase < t; testCase++) {
  10. int n = scanner.nextInt();
  11. int m = scanner.nextInt();
  12. int k = scanner.nextInt();
  13.  
  14. int[] jellyfishValues = new int[n];
  15. int[] gellyfishValues = new int[m];
  16.  
  17. for (int i = 0; i < n; i++) {
  18. jellyfishValues[i] = scanner.nextInt();
  19. }
  20.  
  21. for (int i = 0; i < m; i++) {
  22. gellyfishValues[i] = scanner.nextInt();
  23. }
  24.  
  25. Arrays.sort(jellyfishValues);
  26. Arrays.sort(gellyfishValues);
  27.  
  28. int jellyfishIndex = n - 1;
  29. int gellyfishIndex = m - 1;
  30.  
  31. for (int i = 0; i < k; i++) {
  32. if (jellyfishIndex >= 0 && gellyfishIndex >= 0 && gellyfishValues[gellyfishIndex] > jellyfishValues[jellyfishIndex]) {
  33. jellyfishValues[jellyfishIndex] = gellyfishValues[gellyfishIndex];
  34. gellyfishIndex--;
  35. } else {
  36. break;
  37. }
  38.  
  39. if (i % 2 == 0) {
  40. jellyfishIndex--;
  41. } else {
  42. gellyfishIndex--;
  43. }
  44. }
  45.  
  46. int sum = 0;
  47. for (int value : jellyfishValues) {
  48. sum += value;
  49. }
  50.  
  51. System.out.println(sum);
  52. }
  53.  
  54. scanner.close();
  55. }
  56. }
  57.  
Success #stdin #stdout 0.14s 51208KB
stdin
4
2 2 1
1 2
3 4
1 1 10000
1
2
4 5 11037
1 1 4 5
1 9 1 9 8
1 1 1
2
1
stdout
5
2
20
2