Koko Eating Bananas

Annual Banana Festival is here in Umbristan. The Annual Banana Festival is one of the most renowned cultural celebration in Umbristan, and Koko is very excited because she loves eating bananas and banana foods. Banana smoothie, banana boat, you name it, she loves it.

Out of the n at the fair stands selling bananas, each stand sells a unique banana dish, Koko wants to try all of them. In fact, for the ith stand, Koko wants to have at least min_cals[i] Calories of food (Did you know that Calories and calories are different? 1 Cal = 1 kcal = 1000 cal). During each hour while the fair is open to the public, Koko decides that she can eat up to k Calories of food from one stand.

Problem is, the fair is open to the public for a limited time - h hours to be exact - yet she would like to eat as much as she wants before the fair ends. However, she would like k to be as small as possible, as she is on a diet. You understand her struggle, so you would like to help.

Find the smallest integer k that allows her to eat what she wants before the fair closes for the public.

Parameters

  • min_cals: A list of Calories Koko wants to each from the food of each stand.
  • h: The number of hours the fair opens for.

Result

  • The minimum integer k, as described above.

Examples

Example 1

Input: min_cals = [3, 6, 7, 11], h = 8

Output: 4

Explanation:

When k = 4, Koko can eat from each stand for 1, 2, 2, 3 hours, respectively. Any smaller k will cause her to spend more time to eat, exceeding the time limit.

Constraints

  • 1 <= len(min_cals) <= 10^4
  • len(min_cals) <= h <= 10^9
  • 1 <= min_cals[i] <= 10^9

Try it yourself

Solution

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]
  3

Get premium for instant access to all content and solutions

Upgrade