#2591
Distribute Money to Maximum Children
pupil · 590 · lc easy +29 · verified · 20.5% accepted · 363 likes · top 2%
Description
You have money dollars to distribute among children children. Every dollar must be given out, each child must receive at least 1 dollar, and no child may receive exactly 4 dollars. Return the maximum number of children who receive exactly 8 dollars, or -1 if no valid distribution is possible.
Example 1:
Input: money = 20, children = 3
Output: 1
Explanation:
The maximum number of children with 8 dollars will be 1. One of the ways to distribute the money is:
- 8 dollars to the first child.
- 9 dollars to the second child.
- 3 dollars to the third child.
It can be proven that no distribution exists such that number of children getting 8 dollars is greater than 1.
Example 2:
Input: money = 16, children = 2
Output: 2
Explanation: Each child can be given 8 dollars.
Code
1
2
3