Maximize It!

Sort by

recency

|

1125 Discussions

|

  • + 1 comment

    One more solution, as:-

    from itertools import product 
    
    def get_final_result(values, m):
        final_res = 0
        for vals in product(*values):
            temp = 0
            for val in vals:
                temp += val ** 2
            temp = temp % m
    
            if temp > final_res:
                final_res = temp
        return final_res
    
    k, m = input().split()
    n_list = []
    
    for i in range(int(k)):
        n = list(map(int, input().split()))
        n_list.append(n[1:])
    
    result = get_final_result(n_list, int(m))
    print(result)
    
  • + 1 comment

    I see the same problem... THis one for example has the result of 0 when it should be 16 ((96*96)+(4*4)) % 24) for

    2 24 3 24 48 96 4 24 48 96 24

    Oh well, fun getting that the work...

  • + 2 comments

    Any of you succeed with all the test cases for this problem? I see one of the test cases (Testcase 10) is failing for me.

    Input:

    6 767

    2 488512261 423332742

    2 625040505 443232774

    1 4553600

    4 92134264 617699202 124100179 337650738

    2 778493847 932097163

    5 489894997 496724555 693361712 935903331 518538304

    Expected Output: 763

    My Output: 766

    I'm sure my output is corret.

    Simplified input with squaring inputs and modules 767

    4, 100, 287

    4, 654, 685

    1, 105

    16, 560, 295, 64, 536

    4, 417, 295

    25, 712, 225, 94, 66, 121

    One value from each list

    100 + 4 + 1 + 536 + 4 + 121 => 766

    Looks like the ouput which I got is correct.

    or Did I miss something in understanding the problem statement?

  • + 0 comments

    People asked for an easy to understand way to solve this so I made this, hope this helps

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