You are viewing a single comment's thread. Return to all comments →
import itertools
user_input = input().split()
k = int(user_input[0]) m = int(user_input[1])
lists = []
for _ in range(k): lists.append([int(x) for x in input().split()][1:])
combinations = list(itertools.product(*lists))
squared_combinations = [[x**2 for x in combination] for combination in combinations]
s_max = []
for squared_combination in squared_combinations: if (sum(squared_combination) % m > sum(s_max) % m): s_max = squared_combination
print(sum(s_max) % m)
Seems like cookies are disabled on this browser, please enable them to open this website
Maximize It!
You are viewing a single comment's thread. Return to all comments →
import itertools
user_input = input().split()
k = int(user_input[0]) m = int(user_input[1])
lists = []
for _ in range(k): lists.append([int(x) for x in input().split()][1:])
combinations = list(itertools.product(*lists))
squared_combinations = [[x**2 for x in combination] for combination in combinations]
s_max = []
for squared_combination in squared_combinations: if (sum(squared_combination) % m > sum(s_max) % m): s_max = squared_combination
print(sum(s_max) % m)