def cum_choose(amount, amounts, match_exact=False):
    """
    Choose the top n items in a list that satify a
    cumulative amount. Assumes the amounts have been
    sorted to reflect item preferences.

    amount: int
        Number to choose
    amounts: pandas.Series
        Amounts available
    match_exact: bool, default False
        If True, the amount of the last chosen item
        will be trimmed to match the remaining needed.

    """
    cs = amounts.cumsum()

    if match_exact:
        remaining = amount - cs
        remaining[cs <= amount] = 0
        chosen_amounts = amounts + remaining
        return chosen_amounts[chosen_amounts > 0]
    else:
        return amounts[cs <= amount]