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) {
|
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images