🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"MAXSWT","problem_name":"Maximum Possible Sweetness","problemComponents":{"constraints":"- $1 \\leq T \\leq 2.5*10^5$\n- $1 \\leq N \\leq 10^5$\n- $1 \\leq D \\leq 10^9$\n- $1 \\leq P_i, S_i \\leq 10^9$\n- Sum $N$ over all testcases is atmost $10^6$.","constraintsState":true,"subtasks":"","subtasksState":false,"inputFormat":"- The first line contains an integer $T$, the number of test cases. Then the test cases follow. \n- Each test case contains three lines of input.\n- First line will contain 2 space separated integers $N$ and $D$, the number of different candies and the amount of money Chef has. \n- Second line contains $N$ space separated integers $P_1, P_2, \\ldots, P_N$, where $P_i$ is the price of the $i^{th}$ candy.\n- Third line contains $N$ space separated integers $S_1, S_2, \\ldots, S_N$, where $S_i$ is the sweetness of the $i^{th}$ candy. \n","inputFormatState":true,"outputFormat":"For each testcase, output in a single line, the maximum total sweetness Chef can buy with the money he has, and with at most two candies.","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"3\n2 10\n1 2 \n2 1 \n5 7\n1 2 3 4 5\n1 2 3 4 5\n5 7\n6 6 6 6 6\n5 4 3 2 1","output":"3\n7\n5","explanation":"**TestCase $1$:** Chef can collect both the candies available with the money he has.\n\n**TestCase $2$:** Chef can collect candies at index $[2, 5]$ or $[3, 4]$. In both cases, he will get the total sweetness of $7$.\n\n**TestCase $3$:** Since the price of all candies is the same, it\u0027s always optimal to choose the candies with maximum sweetness. Also, in this case, no more than one candy can be chosen. ","isDeleted":false}}},"video_editorial_url":"https://youtu.be/e7At_Bvg_IY","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"daanish_adm","problem_tester":"","date_added":"30-12-2020","tags":{"0":"daanish_adm","1":"easy","2":"greedy","3":"map","4":"priority","5":"set","6":"start7","7":"vichitr"},"problem_difficulty_level":"Easy","best_tag":"Priority Queue","editorial_url":"https://discuss.codechef.com/problems/MAXSWT","time":{"view_start_date":1627219800,"submit_start_date":1627219800,"visible_start_date":1627219800,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=MAXSWT","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problem statements in [Russian](https://www.codechef.com/download/translated/START7/russian/MAXSWT.pdf) and [Mandarin Chinese](https://www.codechef.com/download/translated/START7/mandarin/MAXSWT.pdf).

Chef goes to a candy store that sells $N$ different candies. For each candy, we know its price and sweetness. Chef has $D$ dollars and can take a maximum of $2$ candies, one in each hand. Find the maximum total sweetness he can buy under the given constraints.

**NOTE:** Since the input-output is large, prefer using fast input-output methods. 
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>