A kid has a budget of exactly ₹100 and wants to buy chocolates. A list of available chocolates is provided, with each chocolate having a specific price.
Your task is to write a program that calculates two separate metrics based on this scenario:
Maximum Quantity: The absolute maximum number of individual chocolates the kid can buy without exceeding the ₹100 budget. To achieve this, the kid should prioritize buying the cheapest chocolates first.
Maximum Variety: The maximum number of different kinds of chocolates the kid can buy. A "kind" of chocolate is defined by its price. To achieve this, the kid should buy one of each of the cheapest unique kinds of chocolate first.
The first line contains a single integer N, the number of chocolates available.
The second line contains N space-separated integers, representing the prices of the chocolates.
Your function should return the max_quantity and max_variety as a pair or a small array/list.
These two calculations are independent of each other. The strategy to maximize quantity is different from the strategy to maximize variety, and they should be computed separately.
5
10 20 30 40 50
4
4
Max Quantity: To buy the most chocolates, the kid buys the cheapest ones: 10 + 20 + 30 + 40 = 100. This uses the full budget and results in 4 chocolates.
Max Variety: The unique prices are 10, 20, 30, 40, 50. To buy the most kinds, the kid buys the cheapest kinds: 10 + 20 + 30 + 40 = 100. This results in 4 different kinds.
5
10 10 10 80 90
3
2
Max Quantity: The prices are [10, 10, 10, 80, 90]. The kid buys the three cheapest chocolates: 10 + 10 + 10 = 30. The budget left is 70, which is not enough for the next cheapest (80). The maximum quantity is 3.
Max Variety: The unique prices are {10, 80, 90}. The kid buys one of the cheapest kind (10), leaving ₹90. Then, they buy one of the next cheapest kind (80), leaving ₹10. This is not enough for the next kind (90). The maximum variety is 2.
The expected time complexity is O(N log N).
0 <= N <= 1000
1 <= Price of each chocolate <= 100
Time limit: 1 sec