Barclays Coding Question - Please provide solution
7316

Programming Challenge Description:
You want to send your friend a package with different things.
Each thing you put inside of a package has such parameters as index number, weight and cost.
The package has a weight limitation.
Your goal is to determine which things to put into the package so that the total weight is less than or equal to the package limit and the total cost is as large as possible.
You would prefer to send a package which has less weight if there is more than one package with the same price.
This is a variation of the Knapsack problem.
Input:
Your program should read lines from standard input. Each line contains the weight that a package can take (before the colon) and the list of things you need to pick from. Each thing is enclosed in parentheses where the 1st number is a thing's index number, the 2nd is its weight and the 3rd is its cost.
Max weight any package can take is <= 100.
There might be up to 15 things you need to choose from.
Max weight and max cost of any thing is <= 100.
Output:
For each set of things produce a list of things (their index numbers separated by comma) that you put into the package. If none of the items will fit in the package, print a hyphen (-).
Test 1
Test Input Download Test Input 81 : (1,53.38,98) (3,78.48,76) (5,30.18,48)
Expected Output Download Test Output 4

Test 2
Test Input Download Test Input 75 : (1,85.31,74) (3,3.98,55) (5,63.69,75) (7,60.02,35) (9,89.95,$78)
Expected Output Download Test Output 2,7

Comments (2)