Diverse Committee Selection

Easy
0/40
0 upvote

Problem statement

A company is forming a 3-member committee for a social event. The pool of available employees consists of a number of men and women. To ensure diversity, the committee must have at least one man and at least one woman.


Given the number of men (M) and women (W) available, your task is to calculate the total number of unique ways a valid 3-member committee can be formed.


A committee is considered invalid if it consists of all men or all women.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first and only line of input contains two space-separated integers, M (number of men) and W (number of women).


Output Format:
Print a single integer representing the total number of valid, diverse committees that can be formed.


Note:
The number of combinations can be large, so be sure to use a 64-bit integer type (like long in Java or long long in C++) for your calculations.
Sample Input 1:
3 3


Sample Output 1:
18


Explanation for Sample 1:
There are 3 men and 3 women.
  Ways to choose 1 man and 2 women: C(3,1) * C(3,2) = 3 * 3 = 9.
  Ways to choose 2 men and 1 woman: C(3,2) * C(3,1) = 3 * 3 = 9.
  Total valid committees = 9 + 9 = 18.


Sample Input 2:
2 4


Sample Output 2:
16


Explanation for Sample 2:
There are 2 men and 4 women.
  Ways to choose 1 man and 2 women: C(2,1) * C(4,2) = 2 * 6 = 12.
  Ways to choose 2 men and 1 woman: C(2,2) * C(4,1) = 1 * 4 = 4.
  Total valid committees = 12 + 4 = 16.


Expected Time Complexity:
The expected time complexity is O(1).


Constraints:
0 <= M, W <= 1000

Time limit: 1 sec
Approaches (1)
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Diverse Committee Selection
Full screen
Console