def knapsack01(obj, weights, capacity):
    """ 0/1 knapsack solver, maximizes profit. weights and capacity integer """
    assert len(obj) == len(weights)
    n = len(obj)
    if n == 0:
        return 0, []
    c = [([0] * (capacity + 1)) for i in range(n)]
    added = [([False] * (capacity + 1)) for i in range(n)]
    for i in range(n):
        for j in range(capacity + 1):
            if weights[i] > j:
                c[i][j] = c[i - 1][j]
            else:
                c_add = obj[i] + c[i - 1][j - weights[i]]
                if c_add > c[i - 1][j]:
                    c[i][j] = c_add
                    added[i][j] = True
                else:
                    c[i][j] = c[i - 1][j]
    i = n - 1
    j = capacity
    solution = []
    while i >= 0 and j >= 0:
        if added[i][j]:
            solution.append(i)
            j -= weights[i]
        i -= 1
    return c[n - 1][capacity], solution
