Maximize It!

Sort by

recency

|

1105 Discussions

|

  • + 0 comments
    from itertools import product
    
    K, M = map(int, input().split())
    a = [list(map(int, input().split()))[1:] for _ in range(K)]
    
    print(max([sum(map(lambda x: x**2, combo)) % M for combo in product(*a)]))
    
  • + 0 comments
    from itertools import product
    
    if __name__ == '__main__':
        k, n = map(int, input().strip().split())
    
        arrays = []
    
        for _ in range(1, k + 1):
            arr = list(input().strip().split())[1:]
            arrays.append(arr)
    
        s_max = 0
    
        for combo in product(*arrays):
            sum_combo = sum(int(x) ** 2 for x in combo)
            current_s_max = sum_combo % n
            s_max = max(current_s_max, s_max)
    
        print(s_max)
    
  • + 0 comments

    Solution

    from itertools import product
    
    k,m = map(int, input().split())
    listy = []
    
    for _ in range(k):
        listy.append(list(map(int, input().split()))[1:])
    
    najw = 0
    for i in product(*listy):
        wartosc = sum(x**2 for x in i)%m
        najw = max(najw, wartosc)
    
    print(najw)
    
  • + 0 comments
    from functools import reduce
    def evaluate(arr):
        sq = list(map(lambda x : x**2, arr))
        sum_1 = reduce(lambda x, y :x+y, sq )
        return sum_1
    
    s = list(map(int, input().split()))
    count_arr = s[0]
    M = s[1]
    Sum = 0
    all_arr = []
    for _ in range(count_arr):
        arr = list(map(int, input().split()))
        all_arr.append(arr[1:])
    combinations = list(product(*all_arr)) 
    result = []
    for comb in combinations:
        result.append(evaluate(list(comb))%M)
    
    print(max(result))
    
  • + 0 comments

    Here is HackerRank Maximize It! in python solution - https://programmingoneonone.com/hackerrank-maximize-it-problem-solution-in-python-programming.html