Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Wood Jojo is a carpenter and now he needs X metres of wood. He is now in a forest with N trees with integer height

Wood Jojo is a carpenter and now he needs X metres of wood. He is now in a forest with N trees with integer height in metres, A1, A2, . . . , AN . He has a special cutting device. The device can be set to a certain height H. After that, it can cuts all the tree that has height more than H at the same time. Then, he will collect the parts that were cut off. Since he is lazy, he only wants to use the cutting device once. Help him to find the maximum integer height H for the device such that the sum of parts that is cut off is at least X meters. It is guaranteed that the sum of all of the tree heights will be more than or equal to X.

Format Input The first line consist of two integers, N and X. The second line consist of N integers, A1, A2, . . . , AN , the height of the trees in metres.

Format Output Output 1 line which consists of an integer H, which is the maximum integer height for the device such that the sum of the parts that will be collected is at least X meters.

Constraints 1 N 105 / 100000 1 Ai , X 1012 / 1000000000000

Sample Input 1 (standard input)

7 10 1 1 2 3 3 3 3

Sample Output 1(standard output)

0

Sample Input 2(standard input)

7 10 2 2 2 3 3 3 3

Sample Output 2(standard output)

1

Note : Use Standard C Language, Function, and Simple Code Input and Output Must Be The Same

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

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

Define marketing concepts.

Answered: 1 week ago

Question

1 what does yellow colour on the map represent?

Answered: 1 week ago