Experimental solution with list sorting with custom comparator instead of DP.
The answer is wrong because the comparator is NOT transitive (A > B > C but A < C).