[Community Puzzle] Advertisements

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @jddingemanse,validated by @cedricdd,@Timinator and @Rafarafa.
If you have any issues, feel free to ping them.

I don’t understand why is the solution for ide test case #20 is discount = 34.0.

If I apply ad #0 for 4 items with prices 20,20,5,4 then I have discount = 40.0.
Items with prices 18,8,6 are valid for both ads, so I assign them to ad #0 because that results the highest discount.
That leaves items with prices 18,8,6 for ad #0 (not enough to apply the ad one more time),
and only the item with price 9 for ad #1 (not enough to apply this bad ad, so I don’t need to loose 6 discount).

On the other hand, if the statement is is to be understood as I need to apply ad #1 to all the items that were unused with ad #0, then items with prices 18,9,8,6 remain for ad #1. So the ad can and must be applied twice, the best (least bad) for customer is to apply for pair 18 & 6, and for pair 9 & 8. That is -14 for the total discount so the total would be 40-14=26.

So I really don’t see how 34 can be a consistent solution. What do I miss?
I already pass test cases 1-19 and 21.

Test 20 “The absolute best is against rule 4”:

  • Apply 20, 20, 18, 8 to ad #0 (4 for 2).
  • Apply 9, 6 to ad #1 (2 for 3).
1 Like

Thanks. I modified my code and now I pass 100%.