minimum total weight hackerrank solution