2.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 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 import java.io.*; import java.util.*; public class Solution { public static int r; public static long tp; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); String[] parts = br.readLine().trim().split(" "); int n = Integer.parseInt(parts[0]); int k = Integer.parseInt(parts[1]); Card[] cards = new Card[n]; for(int i = 0; i < n; i++) { parts = br.readLine().trim().split(" "); int power = Integer.parseInt(parts[1]); cards[i] = new Card(parts[0],power); } solve(n,k,cards); System.out.printf("%d %d",r, tp); } /* 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. Save the answers to the static variables r and tp where: r : int - number of red cards added tp : int - total power of cards in your deck */ public static void solve(int n, int k, Card[] cards) { // TODO } } class Card { public String color; public int power; public Card (String color, int power) { this.color = color; this.power = power; } }
2.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 Apply greedy
The actual incomplete code
import java.io.*; public class Solution { public static void main(String[] args) throws Exception { String[] parts = br.readLine().trim().split(" "); for(int i = 0; i < n; i++) { solve(n,k,cards); /* Parameters: Save the answers to the static variables r and tp where: class Card { public Card (String color, int power) {
|
![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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fbafdf156-60f8-4c1a-a097-2c9b0cc9186e%2F7376dad3-dd9d-43fc-ad6d-ffcb9b32da2f%2Fy7rbprh_processed.png&w=3840&q=75)
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fbafdf156-60f8-4c1a-a097-2c9b0cc9186e%2F7376dad3-dd9d-43fc-ad6d-ffcb9b32da2f%2F1swdwk_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)