Perhaps this is the last time Colin is responsible for setting GXCPC problems. Looking back on the past four years, setting GXCPC problems has always been with Colin in his competitive programming career and is full of rich memories and moving moments. To preserve this wonderful memory, Colin decided to select some representative problems from the problems he had given to the previous GXCPCs to form a new contest: the Grand Prix of Guangxi!
Colin has set a total of $$$n$$$ problems before, and each problem can be described by two parameters: difficulty $$$d_i$$$ and the fun level $$$f_i$$$. Colin will choose some of them to form the contest GP of Guangxi. To make the contest perfect, Colin wants the chosen problems satisfying:
Can you help Colin choose which problems should be included in the contest? Since Colin has not determined the specific situation of the final $$$L$$$ and $$$R$$$, he will ask for the answer for $$$q$$$ pairs of $$$(L_i, R_i)$$$. Please calculate the optimal result for each query.
The first line contains two integers $$$n, q\ (1\le n\le 5000, 1\le q\le 10^6)$$$, representing the number of problems and the number of queries.
For the following $$$n$$$ lines, the $$$i$$$-th line contains two integers $$$d_i,f_i\ (1\le d_i\le 10^5, 1\le f_i\le 10^5)$$$, representing the difficulty and the fun level of the $$$i$$$-th problem.
For the following $$$q$$$ lines, each line contains two integers $$$L_i,R_i\ (1\le L_i\le R_i\le 10^5)$$$, representing a query.
Output $$$q$$$ lines; the $$$i$$$-th line contains a single integer, representing the maximum possible sum of the fun level. If there is no way to choose problems that meet all requirements, output '-1'.
3 310 1720 430 71 3041 5223 25
21 11 -1
For the first query, Colin can choose the first problem and the second problem, the sum of their difficulty $$$=10+20=30\in [1, 30]$$$, and the sum of their fun level $$$=17+4=21$$$.
For the second query, Colin can choose the second problem and the third problem, the sum of their difficulty $$$=20+30=50\in [41, 52]$$$, and the sum of their fun level $$$=4+7=11$$$.
For the third query, there is no way to choose problems that meet all requirements.
| Название |
|---|


