I'm afraid solving your problem in polynomial time is not possible unless P=NP. If one can solve your problem in polynomial time, then using such solution algorithm $P(T,k)$ and [binary search][1] (in the virtual array of subsets of $T$ sorted by their sums, where $k$-th element is accessed with $P(T,k)$), it would be possible to solve the [Subset Sum Problem][2] in polynomial time as well. But the latter problem is NP-complete. [1]: https://en.wikipedia.org/wiki/Binary_search_algorithm [2]: https://en.wikipedia.org/wiki/Subset_sum_problem