Given 3 array of integers A, B, and C each of size 4.
At the beginning you have:-
- A[0] units of item 1,
- A[1] units of item 2,
- A[3] units of item 3,
- A[4] units of item 4.
Cost of one unit of ith item is B[i].
Apart from selling your items in raw form you can also sell your items using following combinations.
- Combination 1:- 3 units of item 1.
- Combination 2:- 2 units of item 1 +3 units of item 2.
- Combination 3:- 1 units of item 1 +1 units of item 2 + 1 units of item 3.
- Combination 4:- 1 units of item 1 +2 units of item 2 + 1 units of item 3 + 2 units of item 4.
Price of ith Combination is C[i].
Calculate and return maximum money you can make in one day with the provided units initially.
> please help
I reformatted your post for easier readability.
Would you mind just giving us a little code yourself? Isolate a single other problem within this program and show us the code. Just to start. Literally just write the arrays or something.
> i am a beginner ... thats why i am asking for help
Yeah, and just giving you the answer will keep you on the beginner step.
Only next week, the question will be harder and you'll be further behind.
Evolution is survival of the fittest. Sure, you've just crawled out of the sea and onto the beach. Those first few steps are damn hard work, but you've got to make them at some point.
If you really want to make it, then you're going to have to work your ass off and apply yourself rigorously to study and problem solving. You can't just "phone it in" week after week.
EDIT: For the record, whoever reported OP is either malicious, or an idiot.
With code... no (unless JLBorges decides to do it, in which case yes).
Normally, this would be a version of the multiply-constrained unbounded knapsack problem, where there are 8 types of objects with their weights equal to the number of components they take. This isn't the hardest problem in the world to write a brute force algorithm for, but if there's an expectation for you to come as close to an optimal solution as is currently known to be possible, you're in for a rough time.
If you still want to brute force it, it basically comes down to testing each possible combination of combined items, then adding the value of the left-over units to the total value of the combinations. If you know how to do parallel programming, that's strongly encouraged here.
-Albatross
However, if this is a beginner problem, the values of A, B, and C might have been carefully chosen so that doing the naive thing will produce the optimal result, and that naive thing would be to:
* Sell as many of combination 4 as possible.
* Sell as many of combination 3 as possible.
* Sell as many of combination 2 as possible.
* Sell as many of combination 1 as possible.
* Sell whatever's left over.