Itās black friday and the supermarket near Ninjaās house is offering a special discount to every Nth customer that generates a bill. You are initially given 2 arrays, āPRODUCTSā and āPRICESā where āPRODUCTS[i]ā represents the ID of the ith product and āPRICES[i]ā represents the price of the ith product per unit. You are also given an integer āDISCOUNTā which represents the discount percentage for every nth customer (i.e. the effective amount to be paid would be ā(100 - discount) / (100 * amountā).
For each customer that visits the store, you are given 2 arrays, āPRODUCTIDā and āQUANTITYā where āPRODUCTID[i]ā represents the ID of the ith product and āQUANTITY[i]ā represents the quantity of the ith product purchased by the customer.
Your task is to implement the following 2 functions:
1. blackFriday(int N, int discount, int[] products, int[] prices) where every Nth customer receives a discount, ādiscountā is the discount percentage, āproductsā contains the product IDs, and āpricesā contains the prices of products.
2. generateBill(int[] productID, int[] quantity) where āproductIDā contains the product IDs and āquantityā contains the quantities of products purchased by the customer.
The first line of input contains an integer āTā denoting the number of test cases to run. Then the test case follows.
The first line contains three space-separated integers āNā, ādiscountā and āSā denoting the customerās getting a discount, discount percentage and number of products.
The next line contains āSā space-separated integers denoting the array āproductsā.
The next line contains āSā space-separated integers denoting the array āpricesā.
The next line of each test case contains an integer āKā denoting the number of queries.
For the next K queries:
The first line contains an integer āSā denoting the number of distinct products purchased.
The next line contains āSā space-separated integers denoting the array āproductIDā.
The next line contains āSā space-separated integers denoting the array āquantityā.
Output Format :
For each test case, return a list containing the bill amount for each customer after discount(if applicable) in the order they generated the bill.
Output for each test case will be printed in a new line.
Note:
Print the result till 5 decimal places
Note:
You do not need to print anything; it has already been taken care of. Just implement the given functions.
1 <= T <= 100
1 <= K <= 1000
1 <= S <= 100
1 <= productID[i], products[i], quantity[i], prices[i] <= 1000
Where āTā denotes the number of test cases,
āKā denotes the number of queries and
āSā denotes the number of products
Time Limit: 1sec
1
2 90 8
5 4 2 8 3 6 7 1
40 10 50 20 90 90 30 20
2
5
1 3 4 5 8
8 5 4 1 6
3
3 4 5
6 3 7
810.00000
85.00000
Customer number1's bill = 8*20 + 5*90 + 4*10 + 1*40 + 6*20 = 810.00000
Customer number2's bill = 6*90 + 3*10 + 7*40 = 850.00000
But since 2 is divisible by 2, after discount price is = 850.00000*10/100 = 85.00000
2
1 72 3
2 3 1
19 53 11
1
3
1 2 3
3 1 3
3 43 2
2 1
101 20
2
2
1 2
1 2
2
1 2
1 1
59.08000
222.00000
121.00000
Can we keep a count of the number of customers to find which customers get the discount?
We can simply start by creating a hashmap that stores each product ID and corresponding price. For each customer, calculating the bill amount is simple, just multiply the quantity by the price of each product they purchased.
We also keep a count of previous customers and increase it as soon as generateBill is called. If this count is divisible by āNā, we simply apply the discount and return the bill amount.
Algorithm:
O(K * S), where āKā denotes the number of queries and āSā denotes the number of distinct products.
Note that in each query, we iterate through each product at most once in each query
Therefore time complexity for each of the āKā queries is at most O(S), the total time complexity is O(K * S).
O(S), where āSā denotes the number of distinct products.
Since we are using a hashmap of size āSā to store our prices, the overall space complexity is O(S).