This is the problem I have been trying to solve:
This was my attempted solution:
The attempt was inspired from the tutorial — Sorting b_i and using a custom two pointer technique for buying multiple products at once. However, it is failing test #8 and I don't know what is the reason (I think that maybe some integer overflow/a small bug is present otherwise my approach is correct). If someone could guide me on how to go about this that'd be great!