#K68922. Water Delivery Challenge

    ID: 32972 Type: Default 1000ms 256MiB

Water Delivery Challenge

Water Delivery Challenge

The city comprises \(n\) neighborhoods and \(m\) water delivery points. Each neighborhood \(i\) requires a certain amount of water, given by \(W_i\). Each delivery point \(j\) has a maximum capacity \(C_j\) and can supply water to neighborhoods in a specific inclusive range from \(L_j\) to \(R_j\) (1-indexed). The water is distributed in the order of the neighborhoods within the given range.

For each delivery point, if the total unsatisfied water demand in its range is less than or equal to its capacity, then all those demands are completely met. Otherwise, water is supplied sequentially until the delivery point's capacity is exhausted. Your task is to determine whether it is possible to satisfy the water demands of all neighborhoods.

Input/Output via standard input and output.

inputFormat

The first line contains two integers \(n\) and \(m\), the number of neighborhoods and water delivery points, respectively.

The second line contains \(n\) integers, where the \(i\)-th integer represents the water demand \(W_i\) of the \(i\)-th neighborhood.

The third line contains \(m\) integers, where the \(j\)-th integer represents the capacity \(C_j\) of the \(j\)-th water delivery point.

The next \(m\) lines each contain two integers \(L_j\) and \(R_j\) (with \(1 \leq L_j \leq R_j \leq n\)), describing the range of neighborhoods the \(j\)-th delivery point can supply.

outputFormat

Output a single line containing YES if all water demands can be met, or NO otherwise.

## sample
4 2
3 2 2 1
5 4
1 2
3 4
YES