There is no simple solution to sort by value, so you have to make a vector of pairs from a dictionary, and sort it using a comparator.
1000 ms 256 Mb Rules for program design and list of errors in automatic problem checking