java.lang.Object
g2501_2600.s2591_distribute_money_to_maximum_children.Solution

public class Solution extends Object
2591 - Distribute Money to Maximum Children.<p>Easy</p> <p>You are given an integer <code>money</code> denoting the amount of money (in dollars) that you have and another integer <code>children</code> denoting the number of children that you must distribute the money to.</p> <p>You have to distribute the money according to the following rules:</p> <ul> <li>All money must be distributed.</li> <li>Everyone must receive at least <code>1</code> dollar.</li> <li>Nobody receives <code>4</code> dollars.</li> </ul> <p>Return <em>the <strong>maximum</strong> number of children who may receive <strong>exactly</strong></em> <code>8</code> <em>dollars if you distribute the money according to the aforementioned rules</em>. If there is no way to distribute the money, return <code>-1</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> money = 20, children = 3</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The maximum number of children with 8 dollars will be 1. One of the ways to distribute the money is:</p> <ul> <li>8 dollars to the first child.</li> <li>9 dollars to the second child.</li> <li>3 dollars to the third child.</li> </ul> <p>It can be proven that no distribution exists such that number of children getting 8 dollars is greater than 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> money = 16, children = 2</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> Each child can be given 8 dollars.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= money <= 200</code></li> <li><code>2 <= children <= 30</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • distMoney

      public int distMoney(int money, int children)