#C9056. Bin Allocation Problem

    ID: 53107 Type: Default 1000ms 256MiB

Bin Allocation Problem

Bin Allocation Problem

You are given b bins and i items. Each bin has a specified capacity and each item requires a certain amount of space. Your task is to determine if it is possible to allocate all items to the bins such that the sum of item sizes in any bin does not exceed its capacity.

Formally, you are given two lists: one containing the capacities of the bins and the other containing the sizes of the items. You need to check if there exists an assignment of items to bins such that for each bin, the total size of the items allocated to that bin is at most its capacity.

You may assume that an item can be placed in a bin if and only if the remaining capacity in that bin is at least the size of the item. The strategy used in many solutions is to sort both lists in descending order and then greedily allocate the largest item to the bin with the largest remaining capacity.

For a bin capacity C and an item of size s, the condition is given by: \[ C \ge s \]

inputFormat

The input is given via standard input and consists of three lines:

  • The first line contains two integers b and i, representing the number of bins and the number of items.
  • The second line contains b space-separated integers representing the capacities of the bins.
  • The third line contains i space-separated integers representing the sizes of the items.

outputFormat

Output a single line to standard output: YES if it is possible to allocate all items according to the rules, or NO otherwise.

## sample
3 4
10 20 15
5 8 12 6
YES

</p>