#C3160. Supply Distribution Problem
Supply Distribution Problem
Supply Distribution Problem
You are given several test cases. In each test case, there are N supplies with given weights and K friends, each with a maximum carrying capacity. The task is to determine whether it is possible to assign each supply to a friend such that the sum of the supplies assigned to any friend does not exceed that friend’s carrying capacity.
Note: A greedy approach is suggested where supplies and friends are sorted in descending order. However, be careful in simulating the distribution. If the total weight of the supplies exceeds the total carrying capacity, the answer is immediately Not Possible
.
Input Format (described below): The first line contains a single integer T, the number of test cases. For each test case, the first line contains two integers, N and K. The second line contains N integers representing the weights of the supplies. The third line contains K integers representing the carrying capacities of the friends.
Output Format: For each test case, output a single line with either "Possible" if the distribution is achievable according to the constraints, or "Not Possible" otherwise.
inputFormat
The input starts with an integer T (the number of test cases).
- For each test case:
- The first line contains two space-separated integers: N and K.
- The second line contains N space-separated integers representing the weights of the supplies.
- The third line contains K space-separated integers representing the carrying capacities of the friends.
outputFormat
For each test case, print a single line containing either "Possible" if a valid distribution exists, or "Not Possible" if it does not.
## sample2
3 2
5 10 15
20 20
4 3
8 5 7 14
10 10 10
Possible
Not Possible
</p>