#K61947. Bookshelf Organization

    ID: 31422 Type: Default 1000ms 256MiB

Bookshelf Organization

Bookshelf Organization

You are given a collection of shelves and books. Each shelf has a maximum capacity (in units), and each book has a thickness. You are asked to answer several queries to determine if a selected group of books can be placed on a specified shelf without exceeding its capacity.

Formally, you are given:

  • An integer \(N\) representing the number of shelves.
  • An integer \(M\) representing the number of books.
  • An integer \(Q\) representing the number of queries.
  • An array \(capacities[1\ldots N]\) where \(capacities[i]\) is the maximum capacity of the \(i\)-th shelf.
  • An array \(thicknesses[1\ldots M]\) where \(thicknesses[j]\) is the thickness of the \(j\)-th book.
  • For each query, a sequence of integers where the first integer indicates the shelf number and the remaining integers represent the indices of the books to be placed on that shelf.

Your task is to determine for each query whether the sum of the thicknesses of the selected books does not exceed the capacity of the chosen shelf. If the books can fit, output Yes; otherwise, output No.

Note: All indices are 1-indexed.

inputFormat

The input begins with a single test case described as follows:

  1. The first line contains three space-separated integers \(N\), \(M\), and \(Q\) — the number of shelves, the number of books, and the number of queries, respectively.
  2. The second line contains \(N\) integers, where the \(i\)-th integer represents \(capacities[i]\), the maximum capacity of the \(i\)-th shelf.
  3. The third line contains \(M\) integers, where the \(j\)-th integer represents \(thicknesses[j]\), the thickness of the \(j\)-th book.
  4. The next \(Q\) lines each describe a query. Each query starts with an integer representing the shelf number, followed by one or more integers indicating the indices of the books to be placed on that shelf.

All tokens are separated by single spaces and each query is in a new line.

outputFormat

For each query, output a single line containing either Yes if the selected books can be placed on the specified shelf without exceeding its capacity, or No otherwise.

## sample
2 4 3
10 15
3 4 2 1
1 1 2
2 3 4
1 4 1
Yes

Yes Yes

</p>