Maximize It!

Sort by

recency

|

1101 Discussions

|

  • + 0 comments

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

  • + 0 comments

    My solution (not very elegant, but passed all tests):

    from itertools import product
    from functools import partial
    
    k, m = map(int, input().split())
    
    def s(lst: tuple, mod: int) -> int:
        return sum(map(lambda x: x**2, lst)) % mod
        
    s_fixed = partial(s, mod=m)
    lsts = []
    
    for _ in range(k):
        n, *arr = map(int, input().split())
        lsts.append(arr)
    
    print(max(map(s_fixed, product(*lsts))))
    
  • + 0 comments
    from itertools import product,combinations
    def f(x):
    return x**2
    k,m=list(map(int,input().split()))
    N,L=[],[]
    s=0
    for i in range(k):
    n,*l=list(map(int,input().split()))
    N.append(n)
    L.append(l)
    for i in product(*L):
            a=(sum(f(x) for x in i))%m
            if a>s: s=a
            print(s)
    
  • + 0 comments
    from itertools import product
    
    K, M = map(int, input().split())
    all_list = list()
    for _ in range(K):
        all_list.append(list(map(int, input().split()))[1:])
    
    S_max = 0
    for item in set(product(*all_list)):
        S = sum(x**2 for x in item) % M
        if S > S_max:
            S_max = S
            
    print(S_max)
    
  • + 0 comments

    from itertools import product k,M = map(int,input().split()) lst = [list(map(int,input().split()))[1:] for _ in range(k)] maxval=0 for items in product(*lst): total= sum(x**2 for x in items)%M maxval = max(total,maxval) print(maxval)