def max_gini(n, ys):
    """Calculates the normalisation coefficient for the generalised Gini index.

    Parameters
    ----------
    n : int
        The number of agents in the simulation.
    ys : list of int
        The agents' cumulative utilities.

    Returns
    -------
    int
        The normalisation coefficient for the generalised Gini index.
    
    """
    total = 0
    aggregate = 0
    k_p1 = 0
    for i, y in enumerate(ys):
        if total + y > 0:
            k_p1 = i + 1
            break
        aggregate += (i+1) * y
        total += y
    return 1 + 2*(aggregate - k_p1*total)/n