#K45727. Fulfilled Orders

    ID: 27818 Type: Default 1000ms 256MiB

Fulfilled Orders

Fulfilled Orders

You are given a stock of \(m\) items and \(n\) orders. Each order requests a specific quantity of an item, identified by its type. For each order, if there is enough stock, it is fulfilled and the stock is decreased accordingly; otherwise, the order is rejected.

Let \(n\) be the number of orders and \(m\) be the number of different item types. The stock is represented by a list of \(m\) integers, where the \(i^{th}\) integer is the initial stock of item \(i\). Each order is given as a pair \((t, q)\), where \(t\) is the 1-indexed item type and \(q\) is the quantity requested.

inputFormat

The input is read from stdin and follows the format below:

  1. The first line contains two space-separated integers \(n\) (the number of orders) and \(m\) (the number of item types).
  2. The second line contains \(m\) space-separated integers, representing the initial stock of each item.
  3. The next \(n\) lines each contain two space-separated integers \(t\) and \(q\), where \(t\) is the item type and \(q\) is the quantity requested.

outputFormat

Output to stdout a single integer — the number of orders that are successfully fulfilled.

## sample
5 3
10 5 20
1 5
2 3
3 10
1 11
2 2
4