Sorting Tom And Jerry Tom And Jerry Decide To Buy Some Toys With The Money They Have All The Toys Are Different But Th 1 (69.73 KiB) Viewed 28 times
Sorting Tom And Jerry Tom And Jerry Decide To Buy Some Toys With The Money They Have All The Toys Are Different But Th 2 (46.03 KiB) Viewed 28 times
Sorting Tom And Jerry Tom And Jerry Decide To Buy Some Toys With The Money They Have All The Toys Are Different But Th 3 (53.79 KiB) Viewed 28 times
Sorting: Tom and Jerry Tom and Jerry decide to buy some toys with the money they have. All the toys are different but their cost can be the same. Tom only buys the toys whose cost is even, and Jerry buys the toys whose cost is odd. Find the maximum number of toys Tom and Jerry can buy respectively. Note Every toy can be bought only once. Function Description In the provided code snippet, implement the provided tom And Jerry (...) method using the variables to print the maximum number of toys Tom and Jerry can buy respectively. You can write your code in the space below the phrase "WRITE YOUR LOGIC HERE". There will be multiple test cases running so the Input and Output should match exactly as provided. The base Output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables. Input Format The first line of input contains three space-separated integers N, T, and J denoting the number of toys in the shop, money with Tom, and money with Jerry respectively. The second line of input contains N space-separated integers denoting the cost of the toys. Sample Input 10 54 75 --denotes N, T, J
Sample Input 10 54 75 12 34 25 32 10 15 20 39 29 30 --denotes N, T, J --denotes cost of N toys Output Format The output contains two space-separated integers denoting the maximum number of toys Tom and Jerry can buy respectively. Sample Output 33 Explanation Tom can buy toys costing 10, 34, 32, 10, 20, 30. Jerry can buy toys costing 25, 15, 39, 29. To buy the maximum number of toys, they will buy the toys which cost low. Hence, Tom will buy the toys costing 10, 10, 20. Sliding Window He cannot buy the next one because he has only 54 as the total amount. Jerry will buy the toys costing 15, 25, 29. He cannot buy the remaining ones because he has only 75 as the total amount. Hence, the answer is 3 3.
1 import java.util.*; 2 import java.io.*; 3 import java.lang. Math; 4 5 6 789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 NNNNNNN N N N N m m m 27 28 90 29 30 31 32 public class Main { 33 } public static int tomAnd Jerry(int N, int T, int J, int[] A) { int[] A = new int [N]; for (int i =) } public static void main (String[] args) { Scanner sc = new Scanner (System.in); //INPUT [uncomment & modify if required] int N = sc.nextInt (); } int T = sc.nextInt (); int J = sc.nextInt (); int[] A = new int [N]; for (int i = 0; i < N;i++) { A = sc.nextInt (); } sc.close(); //OUTPUT [uncomment & modify if required] System.out.print (tomAnd Jerry (N, T, J,A));
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!