#K38002. Fair Team Split
Fair Team Split
Fair Team Split
You are given a list of players with integer skill levels. Your task is to partition the players into two teams such that each team is "fair." A team is considered fair if the difference between the maximum and minimum skill levels within that team does not exceed a given value \(D\). In order to achieve this, you should:
- Sort the skill levels in non-decreasing order.
- Divide the sorted list into two groups: the first half forms the left team and the remaining players form the right team.
- Check if both teams have a skill gap (\(\max - \min\)) of at most \(D\). If yes, output "Possible", otherwise output "Not Possible".
Note: For an odd number of players, the left team will have \(\lfloor N/2 \rfloor\) players and the right team will have the remaining players.
The formula used for the fairness condition on a team with skill levels \(S\) is:
[ \max(S) - \min(S) \leq D ]
inputFormat
The input is read from standard input (stdin). It consists of multiple test cases. The first line contains an integer \(T\) denoting the number of test cases. Then for each test case:
- The first line contains two integers \(N\) and \(D\), where \(N\) is the number of players and \(D\) is the maximum allowable skill gap.
- The second line contains \(N\) space-separated integers representing the players' skill levels.
outputFormat
For each test case, output a single line to standard output (stdout) containing either "Possible" if it is possible to form two fair teams, or "Not Possible" otherwise.
## sample1
4 3
1 3 6 9
Possible
</p>