Candy Collection

  • + 0 comments
    import sys
    from functools import reduce
    n = int(input().strip())
    T = list(map(int, input().strip().split(' ')))
    V = list(map(int, input().strip().split(' ')))
    # Write Your Code Here
    crates = {}
    cost = []
    for i in range(n):
        if T[i] not in crates.keys():
            crates[T[i]] = V[i]
        else:
            cost.append(reduce(lambda x, y: x | y, crates.values()))
            crates = {}
            crates[T[i]] = V[i]
    print(sum(cost))
    

    Shouldn't a crate have all unique Ti's? Why didn't this work? The question seemed simple at the first glance