[Solution] Monks CodeChef Solution 2022 | Solution CodeChef
Problem
There is a town with people and initially, the person has coins. However, some people of the town decide to become monks. If the person becomes a monk, then:
- He leaves the town thereby reducing the number of people in the town by .
- He distributes coins to the remaining people of the town (not necessarily equally). Note that each monk can freely choose his value of , and different monks may choose different values of .
- He takes the remaining coins with him.
For example, initially, if and person decides to become a monk then he can leave the town and can give coins to the person, coin to the person, no coins to the person and take coins along with him while going. Now becomes .
Determine the minimum number of people who have to become monks, so that in the end, everyone remaining in the
town has an equal number of coins.
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the number of people in the town.
- The second line of each test case contains space-separated integers denoting the initial number of coins of everyone in the town.
Is it hot or cold CodeChef Solution
Maximise the Tastiness CodeChef Solution
N Buttons 1 Bulb CodeChef Solution
Valid Minimum CodeChef Solution
High Frequency CodeChef Solution
Output Format
For each test case, output the minimum number of people who have to become monks, so that in the end, everyone remaining in the town has an equal number of coins.
Explanation:
Test case : All the people already have an equal number of coins.
Test case : The person can become a monk and give his coin to the person with coins. After this, both the remaining people will have coins.
Test case : One way of two people becoming monks is as follows:
- The person becomes a monk, and takes his coin with him
- The person becomes a monk, and gives one coin each to the and people
Everyone remaining in the town now has coins.
No comments:
Post a Comment