Created
December 19, 2019 02:02
-
-
Save eguyd/ed0875c057200eecb2ce146d1069ee83 to your computer and use it in GitHub Desktop.
You are given a function . You are also given lists. The list consists of elements. You have to pick one element from each list so that the value from the equation below is maximized: % denotes the element picked from the list . Find the maximized value obtained. denotes the modulo operator. Note that you need to take exactly one element from ea…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
(K, N) = map(int, raw_input().split()) | |
L = list() | |
for i in range(K): | |
l = map(int, raw_input().split()) | |
n = l[0] | |
L.append(l[1:]) | |
assert len(L[i]) == n | |
S_max = 0 | |
L_max = None | |
for l in itertools.product(*L): | |
s = sum([x**2 for x in l]) % N | |
if s > S_max: | |
S_max = s | |
L_max = l | |
print S_max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment