TopCoder SRM 516 Div1 Medium RowsOrdering

1WAしてしまったけど、解法はすんなりたどり着いた。 http://community.topcoder.com/stat?c=problem_statement&pm=11114