#K75607. Conference Room Allocation

    ID: 34457 Type: Default 1000ms 256MiB

Conference Room Allocation

Conference Room Allocation

In this problem, you are given a set of conference rooms and a list of sessions, each with a specified number of attendees. Every room has a seating capacity, and it may host several sessions sequentially as long as the total number of attendees assigned to it does not exceed its capacity. In other words, if a room initially has capacity (C) and it is assigned sessions with attendees (a_1, a_2, \dots, a_k), then we must have (a_1 + a_2 + \dots + a_k \leq C).

A greedy approach can be used to determine whether all sessions can be accommodated. First, sort the list of room capacities and the list of session attendee numbers in descending order. Then, for each session with (a_i) attendees, assign it to the room with the highest remaining capacity (C) such that (a_i \leq C), and update that room's remaining capacity as (C' = C - a_i). If at any point no room can accommodate a session, output NO; otherwise, if all sessions have been assigned, output YES.

inputFormat

The input consists of multiple test cases. Each test case begins with a line containing two integers (R) and (S) ((1 \leq R, S\leq 10^5)), where (R) represents the number of rooms and (S) represents the number of sessions. The next line contains (R) integers specifying the seating capacities of the rooms. The following line contains (S) integers specifying the number of attendees for each session. The test cases are terminated by a line with two zeros (0 0), which should not be processed. All numbers are separated by spaces or newlines.

outputFormat

For each test case, print a single line containing either YES if all sessions can be accommodated or NO otherwise.## sample

3 4
100 50 30
40 20 30 70
2 3
60 100
40 90 20
1 1
50
60
0 0
YES

YES NO

</p>