Sorting: Tom and Jerry Tom and Jerry decide to buy some toys with the money they have. All the toys are different but th
Posted: Fri Jul 08, 2022 6:40 am
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));