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.
k, m = map(int, input().split())
matrix = []
count = 0
def map_square(x):
x = i
for i in range(k):
x= [*map(lambda x: (int(x)**2)%m, input().split())]
x.sort()
matrix.append(x)
matrix.sort(key=lambda x: max(x) )
def calculate_sum_all_elements(matrix:list):
if len(matrix) == 1:
return max(matrix)
else:
lst1 = matrix.pop(0)
lst2 = matrix.pop(0)
lst = [(x+y)%m for x in lst1 for y in lst2]
matrix.insert(0, lst)
return calculate_sum_all_elements(matrix)
print(max(calculate_sum_all_elements(matrix)))
Cookie support is required to access HackerRank
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 →
k, m = map(int, input().split()) matrix = [] count = 0 def map_square(x): x = i for i in range(k): x= [*map(lambda x: (int(x)**2)%m, input().split())] x.sort() matrix.append(x) matrix.sort(key=lambda x: max(x) )
def calculate_sum_all_elements(matrix:list): if len(matrix) == 1: return max(matrix) else: lst1 = matrix.pop(0) lst2 = matrix.pop(0) lst = [(x+y)%m for x in lst1 for y in lst2] matrix.insert(0, lst) return calculate_sum_all_elements(matrix)
print(max(calculate_sum_all_elements(matrix)))