• + 0 comments
    def f(A,i,j):
        if i==j:
            return 0
        f = A[i]
        i,j = min(i,j),max(i,j)
        for a in range(i+1,j+1):
            if (f==1 and A[a]==0) or (f==0 and A[a]==1):
                f = 1
            else:
                f = 0
        return f
     
    def g(A,x,y):
        g = 0
        for i in range(x,y+1):
            for j in range(i,y+1):
                g += f(A,i,j)
    
    def change(a,i):
        if i==0:
            return [a]
        #code to change i number of element in a
    
    def maximizingFunction(a, queries):
        List = []
        for query in queries:
            x = query[0]
            y = query[1]
            k = query[2]
            Max = 0
            for i in range(k+1):
                for A in change(a,i):
                    if g(A,x,y)>Max:
                        Max = g(A,x,y)
        return Max