| VII UnBalloon Contest Mirror |
|---|
| Finished |
During the preparation for the UnBalloon Great Programming Contest, several coaches are testing strategies to assemble the best possible superteam.
The organizers of the event allow the formation of a superteam from a subset of $$$n$$$ available teams. Each team has four types of participants, corresponding to different skill profiles, with their quantities within team $$$i$$$ being represented by four integers $$$(a_i, b_i, c_i, d_i)$$$. To assemble a super team, the organizers can choose any subset of these teams.
After choosing a superteam, the organizers gather all participants from the selected teams and define:
Then, a training session is held with the members of the superteam, with an associated numeric penalty. The training consists of two independent stages:
Immediately after these two stages, two parameters $$$(k, l)$$$ are used to calculate the penalty of the training. The values $$$k$$$ and $$$l$$$ represent the weight of each training stage, and the penalty value is given by the sum of the contributions of both stages.
The coaches want to test different strategies. For this purpose, they will evaluate $$$q$$$ different pairs of weights $$$(k, l)$$$.
Your task is to help the coaches: for each pair of weights $$$(k, l)$$$, determine the maximum penalty that could be achieved by choosing a subset of the teams.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 10^5$$$) — the number of teams and the number of queries.
Each of the next $$$n$$$ lines contains four integers $$$a_i, b_i, c_i, d_i$$$ ($$$0 \le a_i, b_i, c_i, d_i \le 10^4$$$), describing the $$$i$$$-th team.
Each of the next $$$q$$$ lines contains two integers $$$k$$$ and $$$l$$$ ($$$0 \le k, l \le 10^4$$$), representing a pair of weights.
For each of the $$$q$$$ pairs of weights, print one integer: the maximum possible penalty that can be achieved.
2 35 3 4 16 1 3 41 12 00 3
9 14 9
5 45 10 0 39 3 2 37 4 2 22 8 5 64 12 9 81 13 19 27 4
22 60 177 145
| Name |
|---|


