We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Data Structures
  3. Heap
  4. Jesse and Cookies

Jesse and Cookies

Problem
Submissions
Leaderboard
Discussions
Editorial

Jesse loves cookies. He wants the sweetness of all his cookies to be greater than value . To do this, Jesse repeatedly mixes two cookies with the least sweetness. He creates a special combined cookie with:

sweetness Least sweet cookie 2nd least sweet cookie).

He repeats this procedure until all the cookies in his collection have a sweetness .
You are given Jesse's cookies. Print the number of operations required to give the cookies a sweetness . Print if this isn't possible.

Input Format

The first line consists of integers , the number of cookies and , the minimum required sweetness, separated by a space.
The next line contains integers describing the array where is the sweetness of the cookie in Jesse's collection.

Constraints



Output Format

Output the number of operations that are needed to increase the cookie's sweetness .
Output if this isn't possible.

Sample Input

6 7
1 2 3 9 10 12

Sample Output

2

Explanation

Combine the first two cookies to create a cookie with sweetness =
After this operation, the cookies are .
Then, combine the cookies with sweetness and sweetness , to create a cookie with resulting sweetness =
Now, the cookies are .
All the cookies have a sweetness .

Thus, operations are required to increase the sweetness.

Author

vatsalchanana

Difficulty

Easy

Max Score

25

Submitted By

29165

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature