| Contests - ACM Student Chapter - PSUT |
|---|
| Private |
| Spectator |
| JU Cup 2026 |
|---|
| Finished |
Abushogi is in a clothing shop with $$$n$$$ items. The $$$i$$$-th item has a price of $$$a_i$$$ dinars and brings Abushogi a happiness worth of $$$b_i$$$.
The shop has given him an offer he can't refuse: if he buys exactly $$$2$$$ distinct items, he gets a $$$50\%$$$ discount (rounded down) on one of them! However, the shop manager applies the discount based on a specific rule:
Abushogi has exactly $$$k$$$ dinars. He wants to buy exactly $$$2$$$ items to maximize his total happiness without exceeding his budget.Help Abushogi find the maximum total happiness he can achieve, or tell him if it's impossible to afford any pair of items.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — denotes the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 2 \cdot 10^9$$$) — denotes the number of items in the shop and the amount of dinars Abushogi has.
The next $$$n$$$ lines each contain two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le 10^9$$$) — denotes the price and happiness value of the $$$i$$$-th item.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each testcase, print a single integer — the maximum total happiness Abushogi can achieve. If it is impossible to buy exactly 2 items without exceeding $$$k$$$ dinars, print -1.
33 108 56 104 42 1010 1004 1003 510 110 28 3
14200-1
| Name |
|---|

