def best_scores(scores,
                sortidx,
                ref_counts,
                count,
                hyp_str,
                ref_strs):
    """sum together the best scores, taking reference counts into account"""
    out = 0.0
    cursor = -1     # best scores at end of sorted matrix
    while count > 0:
        score = scores[sortidx[cursor]]
        if score == 0:
            # early exit if no more hits to be found
            return out
        refc = ref_counts[sortidx[cursor]]
        refc = min(refc, count)
        out += refc * score
        #print('"{}" <-> "{}": {} * {} = {}'.format(
        #    hyp_str, ref_strs[sortidx[cursor]],
        #    refc, score, refc * score))
        count -= refc
        cursor -= 1
    return out