Maximize It!

Sort by

recency

|

1121 Discussions

|

  • + 0 comments

    from itertools import product A, B = map(int, input().split(" "))

    appended_list = [] for i in range (1, A+1): K = list(map(int, input().split(" "))) all_list= [n for n in K if n != K[0]] appended_list.append(all_list)

    V = list(product(*(appended_list)))

    greatest_value = 0 for j in V: add_num = 0 for l in j:
    add_num = add_num+l2
    current_value = add_num%B if current_value > greatest_value: greatest_value = current_value else: greatest_value = greatest_value

    print(greatest_value)

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