URGENT- Information is present in the screenshot and below. Based on that need help in solving the code for this problem in Java. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply divide-and-conquer algorithm or greedy algorithm in the problem. I have coded it partially and it gives partially correct answer, but seems to not to work for lot of test cases. Can you modify the code so it passes the three test cases given in the screenshot ASAP
The Code-
import java.util.*;
public class Solution { 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(); }
Arrays.sort(r_i); Arrays.sort(s_j);
int i = 0, j = 0; int maxmatchupbyHamiltonia = 0, maxmatchupbyBurrgadia = 0;
while (i < a && j < b) { if (r_i[i] >= s_j[j]) { maxmatchupbyHamiltonia++; i++; } else { maxmatchupbyBurrgadia++; j++; } }
Transcribed Image Text:Sample Input 0
35
5
4
ANO A
1
0
Sample Output 0
30
Sample Input 1
in c0 mm 0 in 0 m
54
8
3
3
4
8
5
1
8
3
Sample Output 1
22
Sample Input 2
TANGO in H
78
12
Sample Output 2
70
Transcribed Image Text:Decisions are happening over battle. Two armies walk onto the battlefield, diametric'ly opposed, foes. They
emerge with a compromise, having opened doors that were previously closed.
They decide that their nations' fate must be addressed with diplomacy. Specifically, the sovereignty of their
nations will be decided with a rap battle between the two nations' government leaders. May the raddest
nation win.
The first nation of Hamiltonia has A leaders, each having a rap proficiency of R₂. The second nation of
Burrgadia has B leaders, each having a rap proficiency of Sj.
If one of the nations has more or fewer leaders than the other, only K rap battles will occur, where
K = min (A, B). The nation with fewer leaders can decide whom among its ranks will be matched against
each of the opposing team's leaders.
In a rap battle, the leader with the greater rap proficiency wins. Let us assume that two representatives are
currently matched up. Representative 1 has a rap proficiency of 5, while Representative 2 has a rap proficiency
of 6. Representative 2 will win in this case. If a tie occurs between two leaders' rap proficiencies, the winner is
the team with more total leaders, i.e., the team who did NOT choose the matchups.
Given the lineups of Hamiltonia and Burrgadia, can you determine the maximum matches each side can win,
assuming that the team with fewer leaders chooses their matchups optimally?
Input Format
Input begins with a line containing two space-separated integers: A and B, the number of leaders of
Hamiltonia and Burrgadia, respectively.
A lines follow, each containing a single integer R, the rap proficiency of Hamiltonia's ith leader.
Blines follow, each containing a single integer S;, the rap proficiency of Burrgadia's jth leader.
Constraints
1 ≤ A, B ≤ 2.105
A & B
0 ≤ Ri, Sj ≤ 10⁹
Output Format
Output contains a line with two space-separated integers W., and W₁.
Wo is the maximum matchups won by Hamiltonia
W, is the maximum matchups won by Burrgadia.
Process or set of rules that allow for the solving of specific, well-defined computational problems through a specific series of commands. This topic is fundamental in computer science, especially with regard to artificial intelligence, databases, graphics, networking, operating systems, and security.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
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.