Rocket Launching
InterviewTime limit2sMemory limit1024 MB
Given buildings at distances X_i with heights H_i, find for each query T the highest altitude Taro can be at by time T after climbing one ladder.
- Level
Medium5 of 10
- Topics
- Sorting, Binary search, Array
- Solved
- No attempts yet
Problem
Taro is an ordinary beaver living in Beaverland. Beaverland measures time in byo (ビョウ).
Beaverland is flat, and the ground is at height 0 m everywhere. Beaverland has one rocket launch site and buildings, numbered 1 to . Building () stands perpendicular to the ground at a distance of m from Taro's house, and its height is m. Each building has a ladder that lets a person climb from the ground to the roof. Taro can walk on the ground at 1 m per byo and climb a ladder at 1 m per byo.
Tomorrow, a rocket carrying Beaverland's first Jupiter probe will launch from the launch site. Taro wants to watch the launch from as high a place as possible by climbing buildings with ladders.
Taro has no alarm clock, so he does not know when he will wake up tomorrow. He therefore makes plans for cases. In plan (), Taro starts moving from his house exactly byo before the launch. For each plan, find the highest altitude he can reach at the moment of launch.
Input
The input is given in the following format.
N Q
X_1 H_1
X_2 H_2
\vdots
X_N H_N
T_1
T_2
\vdots
T_Q
Output
Print lines. The -th line contains an integer, the highest altitude Taro can reach at the moment of launch in plan , where he starts moving from his house exactly byo before the launch.
Constraints
- ()
- ()
- ()
- All input values are integers.