Show problems as
Classic problem #2591EasyMathGreedy

Distribute Money to Maximum Children

Real-world version: Badges at the Token Counter
Tracked in this browser only
Read Distribute Money to Maximum Children on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

An arcade attendant has tokens tokens to hand out across players players waiting at the counter. The house rules are:

  • every token must be handed out;
  • every player must leave with at least one token;
  • no player may leave with exactly four tokens, a count the arcade considers unlucky.

A player who leaves with exactly eight tokens is also given a free badge.

Return the largest number of badges the attendant can award. If no handout satisfies all three rules, return -1.

Examples

Example 1

Input
tokens = 24, players = 3
Output
3

Handing eight tokens to each player uses all 24, gives everyone at least one and leaves nobody on exactly four, so all three players collect a badge.

Example 2

Input
tokens = 10, players = 2
Output
1

Handing out eight and two tokens uses all ten, gives both players at least one and leaves neither on exactly four. One player holds eight, so one badge is awarded.

Example 3

Input
tokens = 12, players = 2
Output
0

Handing out five and seven tokens uses all twelve, gives both players at least one and leaves neither on exactly four. Neither player holds eight, so no badge is awarded.

Example 4

Input
tokens = 1, players = 2
Output
-1

One token cannot give two players at least one each, so no handout satisfies the rules.

Constraints

  • 1 <= tokens <= 200
  • 2 <= players <= 30

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def most_badges(tokens: int, players: int) -> int:
Java
public int mostBadges(int tokens, int players)