0

given two 1D arrays . first array A containing the number of candles as integers , the second B array contains cost of the corresponding number of candles i.e Ai number of candles cost Bi and so on.

we are also given an integer K(total money)

we need to print the maximum number of candles we can purchase whose cost does not increase K(total money). all the data types are non negative integers.

Eg : k=10 A:(2 3 4 5 6 )  B:(4 5 2 10 6)  answer is 10(4+6)
shapiro yaacov
  • 2,308
  • 2
  • 26
  • 39
  • What is your question? – Nanhydrin Jul 09 '15 at 12:10
  • we have two arrays A[] (number of candles) and B[] ( cost of corresponding number of candles). an integer K ( max money with us) . we have to give the maximum number of candles one can buy. – nitish kumar Jul 09 '15 at 12:21
  • That is the task you are working on. What problem are you having with it, or are you asking us to just give you the code for it? – Nanhydrin Jul 09 '15 at 12:23
  • no this is not the task . This is a sub problem that i encountered while working and now i'm stuck with it. my task is a bit complicated so to avoid complications i converted it a simple problem for asking.. – nitish kumar Jul 09 '15 at 12:27
  • i guess i have to use backtracking but i'm unable to apply on it – nitish kumar Jul 09 '15 at 12:28
  • tell me if i got this wrong: each candle costs a different amount and you are looking for the highest number of candles with a sum you have...?? or is the first array the array of number of candles?? – Rct Lynx Jul 09 '15 at 12:31
  • first array is of number of candles. and second array of the cost of corresponding number of candles. the total cost of all number of candles must be <=K(total money). – nitish kumar Jul 09 '15 at 12:37
  • This is the Knapsack problem. http://stackoverflow.com/questions/7774769/how-do-i-solve-the-classic-knapsack-algorithm-recursively – shapiro yaacov Jul 09 '15 at 13:05

1 Answers1

1

https://en.wikipedia.org/wiki/Knapsack_problem

Amount of candles in your cast is value of item, but cost is weight.

Svisstack
  • 16,203
  • 6
  • 66
  • 100