#373
Unrated
Slingshot
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. In order to streamline this process, he comes up with an intriguing idea: instead of hauling manure between two points in a cart behind his tractor, why not shoot it through the air with a giant manure slingshot? (indeed, what could possibly go wrong...)

Farmer John's farm is built along a single long straight road, so any location on his farm can be described simply using its position along this road (effectively a point on the number line). FJ builds NN slingshots (1N1051 \leq N \leq 10^5), where the iith slingshot is described by three integers xix_i, yiy_i, and tit_i, specifying that this slingshot can shoot manure from position xix_i to position yiy_i in only tit_i total units of time.

FJ has MM piles of manure to transport (1M1051 \leq M \leq 10^5). The jjth such pile needs to be moved from position aja_j to position bjb_j. Hauling manure with the tractor for a distance of dd takes dd units of time. FJ is hoping to reduce this by allowing up to one use of any slingshot for transporting each pile of manure. Time FJ spends moving his tractor without manure in it does not count.

For each of the MM manure piles, please help FJ determine the minimum possible transportation time, given that FJ can use up to one slingshot during the process.

입력

The first line of input contains NN and MM. The next NN lines each describe a single slingshot in terms of integers xix_i, yiy_i, and tit_i (0xi,yi,ti1090 \leq x_i, y_i, t_i \leq 10^9). The final MM lines describe piles of manure that need to be moved, in terms of integers aja_j and bjb_j.

출력

Print MM lines of output, one for each manure pile, indicating the minimum time needed to transport it.

예제 입력 1

2 3
0 10 1
13 8 2
1 12
5 2
20 7

예제 출력 1

4
3
10
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.