import java.util.*; public class Solution { public static int maxmatchupbyHamiltonia = 0; public static int maxmatchupbyBurrgadia = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int[] r_i = new int[a]; int[] s_j = new int[b]; for (int i = 0; i < a; i++) { r_i[i] = sc.nextInt(); } for (int i = 0; i < b; i++) { s_j[i] = sc.nextInt(); } int K = Math.min(a, b); Arrays.sort(r_i); Arrays.sort(s_j); int i = 0, j = 0; while (i < a && j < b && i < K && j < K) { if (r_i[i] >= s_j[j]) { maxmatchupbyHamiltonia++; i++; } else { maxmatchupbyBurrgadia++; j++; } } System.out.printf("%d %d\n",maxmatchupbyHamiltonia,maxmatchupbyBurrgadia); } }
import java.util.*; public class Solution { public static int maxmatchupbyHamiltonia = 0; public static int maxmatchupbyBurrgadia = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int[] r_i = new int[a]; int[] s_j = new int[b]; for (int i = 0; i < a; i++) { r_i[i] = sc.nextInt(); } for (int i = 0; i < b; i++) { s_j[i] = sc.nextInt(); } int K = Math.min(a, b); Arrays.sort(r_i); Arrays.sort(s_j); int i = 0, j = 0; while (i < a && j < b && i < K && j < K) { if (r_i[i] >= s_j[j]) { maxmatchupbyHamiltonia++; i++; } else { maxmatchupbyBurrgadia++; j++; } } System.out.printf("%d %d\n",maxmatchupbyHamiltonia,maxmatchupbyBurrgadia); } }
import java.util.*; public class Solution { public static int maxmatchupbyHamiltonia = 0; public static int maxmatchupbyBurrgadia = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int[] r_i = new int[a]; int[] s_j = new int[b]; for (int i = 0; i < a; i++) { r_i[i] = sc.nextInt(); } for (int i = 0; i < b; i++) { s_j[i] = sc.nextInt(); } int K = Math.min(a, b); Arrays.sort(r_i); Arrays.sort(s_j); int i = 0, j = 0; while (i < a && j < b && i < K && j < K) { if (r_i[i] >= s_j[j]) { maxmatchupbyHamiltonia++; i++; } else { maxmatchupbyBurrgadia++; j++; } } System.out.printf("%d %d\n",maxmatchupbyHamiltonia,maxmatchupbyBurrgadia); } }
Information and about the problem is given in the screenshot. To Solve the problem, I have coded a solution in java which while is able to pass few test cases, but seems to fail to pass the other. Logically it seems there is an error. I need help in fixing the code (by adding conditions or modifying it, such that it is able to pass the three test cases mentioned in the screenshot ,(currently it is able to pass 2/3. It should pass all 3).
The code-
import java.util.*;
public class Solution { public static int maxmatchupbyHamiltonia = 0; public static int maxmatchupbyBurrgadia = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int[] r_i = new int[a]; int[] s_j = new int[b]; for (int i = 0; i < a; i++) { r_i[i] = sc.nextInt(); } for (int i = 0; i < b; i++) { s_j[i] = sc.nextInt(); }
int K = Math.min(a, b); Arrays.sort(r_i); Arrays.sort(s_j);
int i = 0, j = 0;
while (i < a && j < b && i < K && j < K) { if (r_i[i] >= s_j[j]) { maxmatchupbyHamiltonia++; i++; } else { maxmatchupbyBurrgadia++; j++; } }
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.