-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2e330f
commit 7f1b441
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Distribute Money to Maximum Children | ||
|
||
## Table of Contents | ||
|
||
1. [Introduction](#introduction) | ||
2. [Problem Description](#problem-description) | ||
3. [Approach](#approach) | ||
4. [Usage](#usage) | ||
5. [Complexity](#complexity) | ||
|
||
## Introduction | ||
|
||
This repository contains a C++ solution to a programming problem. The problem involves distributing a given amount of money to a specified number of children while adhering to certain rules. The goal is to maximize the number of children who receive exactly 8 dollars without anyone receiving 4 dollars. | ||
|
||
## Problem Description | ||
|
||
You are given an integer `money` denoting the amount of money (in dollars) that you have and another integer `children` denoting the number of children that you must distribute the money to. You have to distribute the money according to the following rules: | ||
|
||
- All money must be distributed. | ||
- Everyone must receive at least 1 dollar. | ||
- Nobody receives 4 dollars. | ||
|
||
The task is to return the maximum number of children who may receive exactly 8 dollars if you distribute the money according to the aforementioned rules. If there is no way to distribute the money satisfying these rules, return -1. | ||
|
||
## Approach | ||
|
||
The solution follows the following approach: | ||
|
||
1. If `money` is less than `children`, return -1 as it's not possible to distribute. | ||
2. Subtract one dollar from `money` for each child to distribute one dollar to each child initially. | ||
3. Calculate `ans` as `money / 7` since there are 7 remaining dollars to distribute to make it 8 dollars for some children. | ||
|