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:
- Minimum and Maximum number of pairs in m teams of n people
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Find maximum number that can be formed using digits of a given number
- Given number of matches played, find number of teams in tournament
- Maximum number of line intersections formed through intersection of N planes
- Maximum possible time that can be formed from four digits
- Maximum factors formed by two numbers
- Largest even number that can be formed by any number of swaps
- Number of triangles that can be formed
- Number formed by the rightmost set bit in N
- Number of triangles that can be formed with given N points
- Check if a number is formed by Concatenation of 1, 14 or 144 only
- Maximum subarray sum in array formed by repeating the given array k times
- Length of the smallest number which is divisible by K and formed by using 1's only
- Number of triangles formed from a set of points on three lines
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.