Project Euler #240: Top Dice

  • + 0 comments

    My program is giving correct output but the run time gets exceeded, please help in optimizing the code :)

    from itertools import product

    n1, n2, n3, n4 = map(int,input().split())

    l=[]

    c=0

    for i in range (n2):

    l.append(i+1)
    

    for i in product(l, repeat= n1):

    if (sum(sorted(i, reverse= True) [:n3]) == n4):
    
        c+=1
    

    print (c)