Maximize It!

Sort by

recency

|

1095 Discussions

|

  • + 0 comments

    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))

  • + 0 comments

    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)

  • + 0 comments
    1. k , m = map(int,input().split())
    2. li = []
    3. dp = set()
    4. for i in range (k):
    5. x = list(map(int,input().split()))
    6. li.append(x)
    7. for idx,j in enumerate(li[0]):
    8. if(idx!=0):
    9. dp.add((j**2)%m)
    10. for l in range(1,k):
    11. new_dp = set()
    12. for ind , z in enumerate(li[l]):
    13. if(ind!=0):
    14. n_s_m = (z**2)%m
    15. for ele in dp:
    16. new_dp.add((n_s_m + ele)%m)
    17. dp = new_dp
      1. print(max(dp))
  • + 0 comments
    from itertools import product
    
    numbers = {}
    S = 0
    
    K, M = map(int, input().split())
    
    for i in range(K):
        _, *numbers[i] = map(int, input().split())
    
    S = max(S, max(sum(x ** 2 for x in combo) % M for combo in product(*numbers.values())))
    
    print(S)
    
  • + 0 comments
    from itertools import product
    
    def f(X,m):
        result = 0
        for element in X:
            result += element**2
        return result%m
        
        
    def get_max_combo():
        num_lists, m = map(int, input().split()) # Read
        lists = [] # initialize where to save in the lists
        # save lists from input into lists
        for i in range(num_lists): 
            num_elements, *elements = map(int, input().split())
            lists.append(elements)
        # create combinations of every possible list entry with entries from other list entries 
        combos = list(product(*lists))
        max_f = 0
        for combo in combos:
            current_max = f(combo, m)
            if current_max > max_f:
                max_f = current_max
        print(max_f)
        
        
    get_max_combo()