            else:

                if E[i-1][1] + temp[i-1][p-E[i-1][0]] > temp[i-1][p]:

                    temp[i][p] =  E[i-1][1] + temp[i-1][ p - E[i-1][0] ]

                    garde[i][p] = True

                else:

                    temp[i][p] = temp[i-1][p]

    p,L = P,[]

    for i in range(len(E),0,-1):

        if garde[i][p]:

            L.append(i)

            p -= E[i-1][0]



    return temp[len(E)][P] , L