Difficulty Level : Medium
Submissions : 18
Asked In :
Marks :20
: 0 | : 0
You have been exploring the tomb of some long dead person. There is a treasure room here full of vast riches. However, the door to it requires some trickery to unlock. There are $$$N$$$ blocks of varied lengths available to you. The $$$i$$$-th block has length $$$l_i$$$.
On both sides of the door, you must place one block each. Only when the sum of lengths of the blocks is equal to the width of the door will the door open. The width of the door is $$$W$$$.
So, you should pick two blocks $$$i$$$ and $$$j$$$ such that $$$l_i + l_j = W$$$. Which blocks should you pick?
Two integers on the first line, $$$N$$$ $$$W$$$.
$$$N$$$ integers on the second line where the $$$i$$$-th integer is $$$l_i$$$.
Constraints
$$$1 \leq N \leq 10^6$$$
$$$1 \leq W \leq 10^6$$$
$$$1 \leq l_i \leq 10^6$$$
Any two distinct integers $$$i$$$ and $$$j$$$ such that $$$l_i + l_j = W$$$. If it is impossible, output $$$-1$$$.
7 8 7 5 3 6 9 2 9
2 3
12 9 4 19 14 18 1 14 8 15 19 19 2 9
5 7
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.