Expect to Wait

Given a time-ordered schedule of unicycle drops and grouped requests, compute the total wait time of all requesters for each of several starting unicycle counts, or report infinity if anyone is left waiting.

Medium7Prefix sumBinary searchArrayImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Mayor Adam East wants to improve the public transport network of Harshel city by building stations that lend out unicycles. Anyone who owns a special card can come to a station and request a unicycle or drop one off.

Requesting a unicycle is simple. The person joins a queue. If a unicycle is available, the person at the front of the queue takes one immediately. If no unicycle is available, the people in the queue wait until someone drops a unicycle at the station.

The wait time of a person is the time between the request, that is the moment of joining the queue, and the moment of obtaining a unicycle. A person who never obtains a unicycle has an infinite wait time. The total wait time is the sum of the wait times of all people.

Adam already knows the entire schedule for one day. He knows at which times people request unicycles at the Central Station and at which times they drop them off. The Central Station holds any number of unicycles at the same time. The only thing Adam does not know is how many unicycles to place there at the start of the day, so he gives you several starting counts and asks for the total wait time of each.

Nothing happens after the last operation. If anyone is still in the queue once the last operation has been processed, that person never obtains a unicycle and the total wait time is infinite.

Input

The first line contains nn and qq (1n,q1051 \le n, q \le 10^5), where nn is the total number of unicycle requests and unicycle drops at the Central Station and qq is the number of questions Adam asks.

Each of the next nn lines describes one operation at the Central Station.

  • + t k: kk unicycles are dropped at time tt.
  • - t k: kk people request unicycles at time tt.

Every operation satisfies 1t1091 \le t \le 10^9 and 1k1041 \le k \le 10^4. The operations are given in increasing order of time, so no two operations share a time.

The last line contains qq different integers b1,b2,,bqb_1, b_2, \dots, b_q (0bi1090 \le b_i \le 10^9), the number of unicycles placed at the Central Station at the start of the day.

Output

Print qq lines. The ii-th line contains the total wait time for a day that starts with bib_i unicycles. If that total wait time is infinite, print INFINITY on the line instead.