Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MAXIMUM NUMBERS Jojo gets a big challenge by Bibi to solve a game. The game description is explained below. Given N integers and Jojo should

MAXIMUM NUMBERS

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 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 T 100 1 N 104 0 M 109 0 Ai 109

Sample Input 1 (standard input)

2 5 6 1 2 3 4 5 4 3 4 1 3 8 Sample Output 1 (standard output)

Case #1: 3 Case #2: 1

Sample Input 2 (standard input)

3 3 10 2 9 2 4 11 2 9 1 1 3 2 2 2 2

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.

DO IN C++ LANGUAGE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions