I have used (0-1)knapsack technique to solve this problem
Although this method is expensive due to array intialisation
If best possible combination wasn't a issue we could have sorted the (MempoolTransaction)objects in decresing order and added to
the block.
If you are getting memory error this might be due to processor speed
reduse capacity or number of items
or
f.readlines()[0:500]