Maximize It!

Sort by

recency

|

1120 Discussions

|

  • + 1 comment

    Here's the other method but without taking any inputs for my convenience:

    from itertools import product
    
    A = [24, 48, 96]
    B = [24, 48, 96, 24]
    
    PRODUCT = 0
    for X in product(A, B):
        TOTAL = sum(x**2 for x in X) % int(24)
        PRODUCT = max(TOTAL, PRODUCT)
        print(TOTAL, PRODUCT)
    print(PRODUCT)
    
  • + 0 comments

    I couldn't find a single easy to understand way, So here is mine with extra comments to make it easier

    K, M = map(int, input().split())
    POSSIBLE = {0}
    for i in range(K):
        count, *num = list(map(int, input().split())) #1st number in count, and rest in num denoted by *
        vals = {pow(x, 2, M) for x in num} #num will be squared and its MOD M result will be stored in vals
        POSSIBLE = {(a+v)%M for a in POSSIBLE for v in vals} #Every value in vals is added with every value in POSSIBLE and then MOD M on each, finally stored in POSSIBLE
    print(max(POSSIBLE))
    
  • + 0 comments

    from itertools import product

    num,num1=input().split()

    list1=[]

    for i in range(int(num)):

    k,*list_value=list(map(int,input().split()))
    
    list1.append(list_value)
    

    max_value=0

    for cury in product(*list1):

    tatal_val=sum(x**2 for x in cury)%int(num1)
    
    max_value=max(max_value,tatal_val) 
    

    print(max_value)

  • + 0 comments
    K, M = tuple(map(int, input().strip().split()))
    possible = {0}
    for i in range(K):
        count, *nums = list(map(int, input().split()))
        assert count == len(nums)
        vals = {pow(x, 2, M) for x in nums}
        possible = {(a + v) % M for a in possible for v in vals}
    print(max(possible))
    
  • + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    k,m = map(int, input().split()) inp_list = []

    for _ in range(k): _, *nums = map(int, input().split()) inp_list.append([x * x % m for x in nums])

    curr_results = {0}

    for li in inp_list: new_results = set() for res in curr_results: for ele in li: new_results.add((res + ele) % m) curr_results = new_results print(max(curr_results))