Instead of selecting the group of species based on the maximum sum of calories provided and do the optimization on that group, just loop over each group of species, perform the optimization on that group and return the species that form the longest sustainable food chain.
Instead of selecting the group of species based on the maximum sum of calories provided and do the optimization on that group, just loop over each group of species, perform the optimization on that group and return the species that form the longest sustainable food chain.