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 greedy algorithm or divide and conquer in the problem. Make sure all test cases return expected outputs. Also please provide screenshot of the code actually displaying the outputs with the respective inputs.   The actual incomplete code """ Solves a test case. Parameters: n : int - number of cards available k : int - number of cards to include in Jason's deck cards : array-like - string list of shape (n,2). Each element has two elements:  the first is a string containing the color (either "red" or "blue"). The second  is a string containing the power of the card. Returns: r  : int - number of red cards added tp : int - total power of cards in your deck """ def solve(n,k,cards):     # TODO     pass n,k = list(map(int,input().strip().split(' '))) cards = [list(input().strip().split(' ')) for i in range(n)] red, tp = solve(n,k,cards) print(f"{red} {tp}")

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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 greedy algorithm or divide and conquer in the problem. Make sure all test cases return expected outputs. Also please provide screenshot of the code actually displaying the outputs with the respective inputs.

 

The actual incomplete code

"""
Solves a test case.

Parameters:
n : int - number of cards available
k : int - number of cards to include in Jason's deck
cards : array-like - string list of shape (n,2). Each element has two elements: 
the first is a string containing the color (either "red" or "blue"). The second 
is a string containing the power of the card.

Returns:
r  : int - number of red cards added
tp : int - total power of cards in your deck
"""
def solve(n,k,cards):
    # TODO
    pass

n,k = list(map(int,input().strip().split(' ')))
cards = [list(input().strip().split(' ')) for i in range(n)]

red, tp = solve(n,k,cards)

print(f"{red} {tp}")

 

Jason is on the playtesting team of a new trading card game called Logic: The Unsundering. The game is in the
early prototype stages. As a result, only two major card colors have been implemented: red and blue. Red is
focused primarily on offense and resource maintenance. Blue is mainly focused on defense and board
control.
Each card belongs to one of the two colors and has a power value P₁. Unfortunately, the balancing is
imperfect; red cards are more powerful than blue cards. This is quite unfortunate, but Jason intends to make
the most out of this. If he can build a deck that dominates all other decks, then Jason can show the game
designers this crucial flaw in the game design.
Jason has N cards, each with a color C; and power P₁. He wants to build the strongest deck possible. Out of
all the possible decks, one deck is deemed stronger than another if it has more red cards. If two decks have
the same amount of red cards, the deck with a higher total P across all the cards is more powerful. Jason has
to build a deck containing K cards. Can you help Jason build the strongest deck?
Input Format
Input begins with a line containing two space-separated integers N and K, indicating the number of cards
available and the number of cards allowed in a deck respectively.
N lines follow, each containing two space-separated values C and P; that describe one card's color and
power respectively. C is a string with a value of either "red" or "blue" (without quotes). P; is an integer.
Constraints
1≤K≤N≤3.105
C₂ € {red, blue}
0 ≤ P ≤ 10⁹
Output Format
Output contains two space-separated integers R and TP. R is the number of red cards in Jason's deck. TP is
the total P₁ of the cards in the deck.
Transcribed Image Text:Jason is on the playtesting team of a new trading card game called Logic: The Unsundering. The game is in the early prototype stages. As a result, only two major card colors have been implemented: red and blue. Red is focused primarily on offense and resource maintenance. Blue is mainly focused on defense and board control. Each card belongs to one of the two colors and has a power value P₁. Unfortunately, the balancing is imperfect; red cards are more powerful than blue cards. This is quite unfortunate, but Jason intends to make the most out of this. If he can build a deck that dominates all other decks, then Jason can show the game designers this crucial flaw in the game design. Jason has N cards, each with a color C; and power P₁. He wants to build the strongest deck possible. Out of all the possible decks, one deck is deemed stronger than another if it has more red cards. If two decks have the same amount of red cards, the deck with a higher total P across all the cards is more powerful. Jason has to build a deck containing K cards. Can you help Jason build the strongest deck? Input Format Input begins with a line containing two space-separated integers N and K, indicating the number of cards available and the number of cards allowed in a deck respectively. N lines follow, each containing two space-separated values C and P; that describe one card's color and power respectively. C is a string with a value of either "red" or "blue" (without quotes). P; is an integer. Constraints 1≤K≤N≤3.105 C₂ € {red, blue} 0 ≤ P ≤ 10⁹ Output Format Output contains two space-separated integers R and TP. R is the number of red cards in Jason's deck. TP is the total P₁ of the cards in the deck.
Sample Input 0
53
red 1
red 1
blue 5
blue 7
blue 9
Sample Output 0
2 11
Sample Input 1
63
blue 13
blue 8
blue 2
blue 6
red 6
blue 2
Sample Output 1
1 27
Sample Input 2
74
red 4
blue 6
red 3
red 12
red 8
blue 1
red 3
Sample Output 2
4 27
Transcribed Image Text:Sample Input 0 53 red 1 red 1 blue 5 blue 7 blue 9 Sample Output 0 2 11 Sample Input 1 63 blue 13 blue 8 blue 2 blue 6 red 6 blue 2 Sample Output 1 1 27 Sample Input 2 74 red 4 blue 6 red 3 red 12 red 8 blue 1 red 3 Sample Output 2 4 27
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY