How to Optimise my Time Optimisation Algorithm
You're trying to solve a knapsack problem&nbsp;&ndash; you're trying to choose items of maximum value, given a constraint on their total size. These problems are NP-complete but can be solved reasonably efficiently in practice. The standard technique is to use dynamic programming. This gives a solution in time polynomial in $N$ and&nbsp;$T$. This is still, technically, an exponential-time algorithm (since an input of length&nbsp;$\ell$ could give $T$ as large as&nbsp;$2^\ell$) but it works well in practice.

I won't give details of how to do the dynamic programming, since knapsack is one of the standard examples of the technique so it's easy to find the details online and in textbooks.