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 formed by the rightmost set bit in N
- Check if a number is formed by Concatenation of 1, 14 or 144 only
- Number of triangles that can be formed with given N points
- Maximum subarray sum in array formed by repeating the given array k times
- Greatest number less than equal to B that can be formed from the digits of A
- Number of triangles formed from a set of points on three lines
- Check if the large number formed is divisible by 41 or not
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.