Question: Solve this problem in C: S Maximum Addition Jojo gets a big challenge by Bibi to solve a game. The game description is explained below.
Solve this problem in C:
S

Maximum Addition Jojo gets a big challenge by Bibi to solve a game. The game description is explained below. Given N integers and Jojo should determine the length of the longest segment such that if we add all the element of the segment, the result is less than or equal to M. The definition of a segment is a set of consecutive elements in a part of an array. For example, given array with 5 element {2,3,4,1,5), then some valid segments are {2,3,4}, {3,4,1,5},{4}, and etc. Jojo is too lazy to finish this game and he asks you to help him finish this game. Format Input Input consists of one integer T, number of test case given by Bibi. For each test case, there are N and M, length of the array (or number of element inside the array) and the limitation of the summation result of the segment. Next line contains N integers A which describe the element inside the array. Format Output Output should be expressed in format "Case #X: Y" -X is the number of the test case, and followed by one integer Y , the length of the longest segment which the summation result (of all the elements inside it) less than or equal to M. If there is no solution exist, output - 1. Constraints 1 s T s 100 1sNs 104 05 M s 1015 OSA $10 Sample Input 1 (standard input) 2 O 1 2 3 4 5 43 4138 Sample Output 1 (standard output) Case #1: 3 Case #2: 1 Sample Input 2 (standard input) 3 3 10 292 411 2911 32 222 Sample Output 2 (standard output) Case #1: 1 Case #2:3 Case #3:1 Explanation For Sample Input 1 test case 1, we can see that the longest segment which has the summation result less than or equal to 6 is the first 3 elements. If we sum all the first 3 elements, the result of the summation is 6. There is no other configuration which has length more than 3. Thus, the output is 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
