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. B lines follow, each containing a single integer Sj, the rap proficiency of Burrgadia's jth leader. Constraints 1 ≤ A, B ≤ 2.105 A ‡ B 0≤ Ri, Sj ≤ 10⁹
Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible (nlogn or n at best, no n^2). Apply divide-and-conquer
Output Format
Output contains a line with two space-separated integers W_a and W_b.
- W_a is the maximum matchups won by Hamiltonia
- W_b is the maximum matchups won by Burrgadia.
Sample Input 0
3 5
5
4
4
0
2
4
1
0
Sample Output 0
3 0
Sample Input 1
5 4
8
3
3
4
8
5
1
8
3
Sample Output 1
2 2
Sample Input 2
7 8
10
2
8
12
1
9
12
6
0
13
1
9
8
5
1
Sample Output 2
7 0
The actual code
""" Parameters: Returns: s_i = [int(input()) for i in range(a)] win_a, win_b = solve(a,b,s_i,r_j) print(f"{win_a} {win_b}") |
Step by step
Solved in 4 steps with 2 images