Given two integers N and M which denote the number of persons of Type1 and Type2 respectively. The task is to find the maximum number of teams that can be formed with these two types of persons. A team can contain either 2 persons of Type1 and 1 person of Type2 or 1 person of Type1 and 2 persons of Type2.
Input: N = 2, M = 6
(Type1, Type2, Type2) and (Type1, Type2, Type2) are the two possible teams.
Input: N = 4, M = 5
Approach: A greedy approach is to choose 2 persons from the group which has more members and 1 person from the group with lesser members and update the count of persons in each of the group accordingly. Termination condition will be when no more teams can be formed.
Below is the implementation of the above approach:
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Given number of matches played, find number of teams in tournament
- Minimum and Maximum number of pairs in m teams of n people
- Find maximum number that can be formed using digits of a given number
- Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle
- Permutations to arrange N persons around a circular table
- Maximize the total profit of all the persons
- Probability that two persons will meet
- Minimum time required to complete a work by N persons together
- Minimum cost to buy N kilograms of sweet for M persons
- Time taken by two persons to meet on a circular track
- Find last 2 survivors in N persons standing in a circle after killing next to immediate neighbour
- Number of triangles that can be formed with given N points
- Greatest number that can be formed from a pair in a given Array
- Maximum possible time that can be formed from four digits
- Largest even number that can be formed by any number of swaps
- Check if a right-angled triangle can be formed by the given coordinates
- Count of Substrings that can be formed without using the given list of Characters
- Largest square which can be formed using given rectangular blocks
- Check if a given string can be formed using characters of adjacent cells of a Matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.