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⁹

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter19: Probabilistic Dynamic Programming
Section19.3: How To Maximize The Probability Of A Favorable Event Occurring
Problem 1P
icon
Related questions
Question

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 algorithm in the problem. Make sure all test cases return expected outputs.

Hint: Apply bisection method/modules

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

"""
Solves a test case

Parameters:
a   : int        - number of leaders in Hamiltonia
b   : int        - number of leaders in Burrgadia
s_i : array-like - rap proficiencies of Hamiltonia's leaders
r_j : array-like - rap proficiencies of Burrgadia's leaders

Returns:
win_a : int - number of wins from Hamiltonia
win_b : int - number of wins from Burrgadia
"""
def solve(a,b,s_i,r_j):
    # TODO
    
a,b = list(map(int,input().strip().split(" ")))

s_i = [int(input()) for i in range(a)]
r_j = [int(input()) for i in range(b)]

win_a, win_b = solve(a,b,s_i,r_j)

print(f"{win_a} {win_b}")

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 S₁.
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 S;, the rap proficiency of Burrgadia's jth leader.
Constraints
1 ≤ A, B ≤ 2.105
A + B
0 ≤ Ri, S; ≤ 10⁹
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 S₁. 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 S;, the rap proficiency of Burrgadia's jth leader. Constraints 1 ≤ A, B ≤ 2.105 A + B 0 ≤ Ri, S; ≤ 10⁹
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Probability Problems
Learn more about
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole