14351 - 2024_DS_Summer_Exam1_pD   

Description

There are n gas stations on a highway, the i-th station is located at the xi km of the highway, and you can get vi unit of fuel (an unit of fuel can drive 1 km) if you stop and refuel at this station. Also, you can't stop at the i+1, i+2, ..., n-th station if you don't stop at the i-th station.

Now you are at the 0 km of the highway and your car has V unit of fuel. Besides, there are q places you want to visit, the i-th place is located at the pi km of the highway.  Now, for each place, answer at least how many gas station you need to stop in order to reach the place.

Hint

Let Ti be the total unit of fuel you will have if you stop at 1, 2, ... i-th station. Then TiV + v1 + v2 + ... + vby definition, which can be computed in O(n) time using the following recurrence:

  • T0 = (We define T0 as the total unit of fuel if you don't stop at any station)
  • Ti = Ti-1 + vi, i = 1, 2, ..., n

Input

The first line contains two integers: n, q, V

For the next n lines, each line contains two integers: xi, vi (i = 1, 2, ..., n).

The last line contains q integers: p1, p2, ..., pn.

Constrain

  • n, q ≤ 105
  • 1 ≤ x1 < x2 < ... < xn ≤ 109
  • 1 ≤ vi ≤ 109, i = 1, 2, ..., n
  • 1 ≤ pi ≤ 109, i = 1, 2, ..., q

Output

Output n lines, each line contains one integer: the answer of the i-th place. If it is impossible to reach the place, output -1.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss