Project Euler #201: Subsets with a unique sum

  • + 0 comments

    I simplified the code.but stil showing timeout error for few test cases.anybody have an idea?

    from itertools import combinations sm_r=set() sm_l=set() start=list(map(int,input().split())) n,m=start[0],start[1] array=list(map(int,input().split())) c_l=list(combinations(array,m))

    for pair in c_l: sm=sum(list(pair)) if sm not in sm_l: sm_l.add(sm) else: sm_r.add(sm) print(sum(sm_l.difference(sm_r)))