Bob and Candies
Practice
3.9 (107 votes)
Easy
Problem
76% Success 2152 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Little Bob comes to you for candies as you are his favorite coder! He wants X candies. You have N bags and the ith bag contains A[i] candies.

You can give him a set of one or more bags such that the sum of candies in those bags is EXACTLY equal to X. Bob wants to find smallest such set of bags. If there are multiple smallest such sets than Bob wants the lexicographically smallest set of such bags.

See the sample test cases for more clarity.

Input:
The first line contains two space-separated integers N and X.
The second line contains N integers, the number of candies in each bag.

Output:
Print the indices of the bags that you give to Bob. If it is not possible to form such a set, print -1.

Constraints:
1 ≤ N ≤ 20
1 ≤ X ≤ 106
1 ≤ A[i] ≤ 106

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
DatastructuresSegment TreesXORAdvanced Data StructuresData StructuresModular exponentiationSegment treeModulo arithmetic
Points:30
Tags:
Dynamic ProgrammingRecruitMediumAlgorithmsReadyApproved
Points:20
2 votes
Tags:
Ad-HocBasic ProgrammingApprovedEasy