def sort_by(empdist, scores, reward=True):
    """
    Sort the support of an empirical distribution according to a target score.
    :param empdist: empirical distribution
    :param scores: target scores
    :param reward: polatiry of the scoring function (reward vs penalty)
    :return: a sorted sequence k_0^(N-1) where N is the size of the support and each k_i is an element of the support
    """
    return sorted(range(len(empdist)), key=lambda i: scores[i], reverse=reward)