#C5452. Efficient Assignment of Items to Containers
Efficient Assignment of Items to Containers
Efficient Assignment of Items to Containers
You are given a set of containers and a set of items. Each container has a maximum weight capacity \(W_i\) and each item has a weight \(w_j\). The goal is to determine if it is possible to assign every item to one of the containers such that the total weight assigned to any container does not exceed its capacity.
You can assume that items can be placed in any container as long as the weight does not exceed the container's capacity. A greedy strategy, where items are sorted in descending order and placed in the container with the largest available capacity that fits the item, is sufficient for this problem.
Input: The first integer is the number of containers. The next set of integers represents the capacity of each container. Then follows an integer representing the number of items, followed by the weights of the items.
Output: Output YES if it's possible to assign all items without exceeding any container's capacity, otherwise output NO.
inputFormat
The input is given via standard input (stdin) in the following format:
C W1 W2 ... WC I w1 w2 ... wI
Where:
C
is the number of containers.W1, W2, ... WC
are the maximum weight capacities of the containers.I
is the number of items.w1, w2, ... wI
are the weights of the items.
outputFormat
Output a single line with either "YES" if the items can be assigned under the constraints, or "NO" if not.
## sample3
50 60 70
5
20 30 50 10 40
YES