#K39897. Inventory Fulfillment

    ID: 26522 Type: Default 1000ms 256MiB

Inventory Fulfillment

Inventory Fulfillment

You are given an initial inventory of items and a series of requests. Each request consists of several pairs of an item ID and a required quantity. For each request, check if the inventory has sufficient quantity for every requested item. If the request can be fully satisfied, deduct the requested quantities from the inventory and output "Yes"; otherwise, output "No" and leave the inventory unchanged.

The inventory update is performed sequentially on the set of requests. That is, if a request is fulfilled, the inventory changes for subsequent requests.

Input Format:

  • First, an integer \(N\) representing the number of different item types in the inventory.
  • Next \(N\) lines, each containing two integers: the item ID and its available quantity.
  • An integer \(M\) representing the number of requests.
  • Then \(M\) lines follow, each representing a request. Each request starts with an integer \(k\) (number of item types requested), followed by \(k\) pairs of integers representing the item ID and the required quantity.

Output Format:

  • Output \(M\) lines, one for each request, containing either "Yes" if the request can be fulfilled (and inventory is updated), or "No" if it cannot be fulfilled.

Constraints:

  • \(0 \leq N \leq 10^5\)
  • \(0 \leq M \leq 10^5\)
  • Item IDs and quantities are positive integers.

Example

For an inventory with 4 items:

4
1 10
2 5
3 8
4 2

And 3 requests:

3
2 1 5 3 3
2 1 6 4 1
1 2 5

The output should be:

Yes
No
Yes

inputFormat

The input is read from standard input (stdin) in the following format:

  • An integer \(N\) specifying the number of item types in the inventory.
  • \(N\) lines each containing two space-separated integers: the item ID and its quantity.
  • An integer \(M\) specifying the number of requests.
  • \(M\) lines, each representing a request. Each request starts with an integer \(k\) (the number of different items requested) followed by \(k\) pairs of integers, each pair representing an item ID and the required quantity.

outputFormat

For each request, output a single line to the standard output (stdout) containing either "Yes" if the request is fully satisfied (and the inventory is updated accordingly) or "No" if it cannot be satisfied.

## sample
4
1 10
2 5
3 8
4 2
3
2 1 5 3 3
2 1 6 4 1
1 2 5
Yes

No Yes

</p>