from typing import List
import math


def idcg_score(true_set: List[float], predicted_set: List[float], p=None):
    """
    Ideal Discounted Cumulative Gain: sorts all relevant documents in the corpus by their relative relevance,
    producing the maximum possible DCG through position p
    """
    p = p or len(true_set) - 1
    predicted = sorted(true_set, reverse=True)
    return sum((2 ** r - 1) / math.log2(i + 1) for i, r in enumerate(predicted[:p], 1))