#C9478. Task Assignment to Servers

    ID: 53575 Type: Default 1000ms 256MiB

Task Assignment to Servers

Task Assignment to Servers

You are given n servers and m tasks. Each server has a specified capacity, and each task requires a certain amount of resource. Your goal is to determine if it is possible to assign each task to some server such that no server's total assigned tasks exceed its capacity.

Formal Problem Statement:

Let \(c_1, c_2, \ldots, c_n\) be the capacities of the servers, and let \(d_1, d_2, \ldots, d_m\) be the demands of the tasks. The question is whether there exists an assignment of tasks to servers such that for every server, the sum of the demands of the tasks assigned to that server does not exceed its capacity.

You are encouraged to use a greedy strategy: sort the servers and tasks in descending order and try to assign the largest tasks to the servers with the largest remaining capacity.

inputFormat

The first line of input contains two space-separated integers: n (the number of servers) and m (the number of tasks).

The second line contains n space-separated integers representing the capacities of the servers.

If m > 0, the third line contains m space-separated integers representing the demands of the tasks. If m = 0, the third line will be empty.

outputFormat

Output a single line containing YES if it is possible to assign all tasks to the servers without overloading any server; otherwise, output NO.

## sample
3 4
10 20 30
5 10 15 20
YES