#C11064. Maximum Team Formation
Maximum Team Formation
Maximum Team Formation
You are given a list of employees' skill levels and an integer threshold K. Your task is to form as many teams as possible where each team consists of exactly two employees and the sum of their skills is at least K. Each employee can be used in at most one team.
In mathematical terms, given a sorted array of skills, find the maximum number of pairs \( (i, j) \) such that:
[ \text{skill}[i] + \text{skill}[j] \ge K ]
where each employee is used at most once.
This problem can be solved efficiently using a greedy approach with a two-pointer technique.
inputFormat
The first line of input contains an integer T denoting the number of test cases. Each test case is described as follows:
- The first line of each test case contains two integers N and K, where N is the number of employees and K is the threshold skill sum for forming a team.
- The second line contains N space-separated integers representing the skill levels of the employees.
Note: \(K\) is the minimum required sum for a team, i.e., for any valid team, if \(a\) and \(b\) are the chosen employees' skills then \(a+b \ge K\).
outputFormat
For each test case, output a single integer on a new line representing the maximum number of teams that can be formed under the given condition.
## sample2
5 5
1 3 5 2 4
4 5
1 2 2 4
2
1
</p>