#C4026. Truck Delivery Assignment Problem
Truck Delivery Assignment Problem
Truck Delivery Assignment Problem
In this problem, you are given multiple test cases. For each test case, you will receive a list of trucks with their maximum weight capacities and a list of delivery weights. Your task is to determine if it is possible to assign all deliveries to the trucks without exceeding any truck's capacity.
To do so, sort the trucks and deliveries in descending order. For each delivery, assign it to the first truck that has enough remaining capacity. If all deliveries are successfully assigned, output "Possible"; otherwise, output "Impossible".
Mathematically, if a truck has an initial capacity C and is assigned a delivery of weight w, the new capacity becomes
$$C' = C - w.$$
inputFormat
The first line contains an integer T, the number of test cases. Each test case consists of the following four lines:
1. An integer n — the number of trucks.
2. n space-separated integers representing the maximum weight capacity of each truck.
3. An integer m — the number of deliveries.
4. m space-separated integers representing the weight of each delivery.
outputFormat
For each test case, output a single line containing either "Possible" if it is possible to assign all deliveries without overloading any truck, or "Impossible" if not.## sample
5
3
10 5 15
5
2 4 6 8 5
2
8 8
3
9 4 3
2
5 5
3
3 2 1
1
10
1
11
3
10 10 10
3
10 10 10
Possible
Impossible
Possible
Impossible
Possible
</p>