As it is the Valentines month, Puchi's girlfriend asks him to take her shopping. He,…
- User
As it is the Valentines month, Puchi's girlfriend asks him to take her shopping. He, being the average bloke, does not have a lot of money to spend. Hence, decides to buy each item from the shop that offers the best price on it. His girlfriend wants to buy N items. Each item is available on M shops . Being the Valentine Season, shops have the products on a discounted price. But, the discounts are in the form of successive discounts. Each shop has a successive discount of order-3 on each of the N products.
Find, for each item, the shop that offers the best price on it. You may assume that the base price of each item is same on all shops. Note: A successive discount of 25% and 50% on an item of Rs 1000, means getting a discount of 50% on the new price, after getting a discount of 25% on original price, i.e item is available at Rs 750 after a 25% discount , and successively at Rs 375 after two successive discounts of 25 and 50. Input: First line contains T the number of test cases. T test cases follow. First line of each test case contains two space-separated integers N and M , the number of items and the number of shops respectively. It is followed by description of N products. Each product description consists of M lines with 3 integers each, the successive discounts offered on that product.Output: Print N space separated integers i.e for the i'th product, print the index (1 ≤ index ≤ M) of the shop that offers the best price for that product. In case of multiple shops offering the same discount, output the one with lower index.
Constraints: 1 ≤ N, M ≤ 1000 0 ≤ Discounts ≤ 100
Large I/O files.
SAMPLE INPUT 2 1 3 20 20 50 30 20 0 60 50 0 2 2 20 20 20 30 20 40 10 100 90 35 60 50
SAMPLE OUTPUT 3 2 1
Assistant
import sys def main(): input = sys.stdin.read data = input().split() ptr = 0 T = int(data[ptr]) ptr += 1 for _ in range(T): N = int(data[ptr]) M = int(data[ptr + 1]) ptr += 2 res = [] for _ in range(N): best_shop = 1 min_product = None for shop_idx in range(1, M + 1): d1 = int(data[ptr]) d2 = int(data[ptr + 1]) d3 = int(data[ptr + 2]) ptr += 3 product = (100 - d1) * (100 - d2) * (100 - d3) if (min_product is None) or (product < min_product) or (product == min_product and shop_idx < best_shop): min_product = product best_shop = shop_idx res.append(str(best_shop)) print(' '.join(res)) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.