We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Itertools
- Maximize It!
- Discussions
Maximize It!
Maximize It!
Sort by
recency
|
1095 Discussions
|
Please Login in order to post a comment
import itertools n = input() n = n.split(" ") n = list(map(int, n)) k = n[0] m = n[1] s = 0 finallist = [] for i in range(0, k): n = input() n = n.split(" ") n = list(map(int, n)) n = n[1:] n = [i**2 for i in n] finallist.append(n) combinations = list(itertools.product(*finallist)) result = [] for i in combinations: result.append(sum(i)%m) print(max(result))
import itertools
# Read input K, M = map(int, input().split()) lists = []
# Reading each list for _ in range(K): data = list(map(int, input().split())) lists.append(data[1:]) # Skip the first element as it's the size N
# Generate all possible combinations (one element from each list) max_s = 0 # To track the maximum S
# Iterate through all combinations for combo in itertools.product(lists): # Calculate S for the current combination s = sum(x * 2 for x in combo) % M # Update the maximum S if needed max_s = max(max_s, s)
Output the result
print(max_s)