Generation

generate functionSat, 11 Feb 2023

# Grocery Store 2 You are the owner of a grocery store. You have a report of sales of N products of the store over the last M days. Given this data, you must calculate the best selling product cumulatively on each day. If there is a tie, you must print the product with the smallest index. Input Format The first line contains two integers M and N. denoting the number of days and the number of products,respectively. The i th of the next lines contains space-separated integers, A[i][j], where A[i][j] denotes the number of units of the j th product sold on the ith day. Output Format Print m lines, where the i th line contains the index of the best selling product on the ith day

``````m = int(input())
n = int(input())
A = []
for i in range(m):
A.append([int(j) for j in input().split()])
cumulatives = [[] for i in range(n)]
for i in range(m):
curr_max = 0
for j in range(n):
cumulatives[j].append(sum(A[:i+1])[j])
if cumulatives[j][i] > curr_max:
curr_best_sellers = [j + 1]
curr_max = cumulatives[j][i]
elif cumulatives[j][i] == curr_max:
curr_best_sellers.append(j + 1)
print(min(curr_best_sellers))``````