from typing import List


def knapsack(amount: int, weights: List[int]) -> int:
    """
    Return the closet sum to ``amount`` given ``weights``.

    :time: O(m * n)  where m is the amount of weights and n is the amount
    :space: O(n) where n i the amount
    """
    sums = [0] * (amount + 1)
    for weight in weights:
        for val in range(weight, amount + 1):
            sums[val] = max(sums[val], sums[val - weight] + weight)
    return sums[-1]