import math


def normalize_dict(dictionary, x, y):
    """
    Normalize values in dictinoary to be in range [x, y]

    :param dictionary:
    :param x: range min
    :param y: range max
    :return: dict with values changed accordingly
    """
    min_value = min(dictionary.values())
    max_value = max(dictionary.values())
    if max_value <= y and min_value >= x:
        return dictionary

    #  normalize to [0, 1]
    range1 = max_value - min_value
    if not range1:
        range1 = 1
    for key in dictionary:
        dictionary[key] = (float(dictionary[key]) - min_value) / range1

    # then scale [x,y] and take ceiling
    range2 = y - x
    for key in dictionary:
        dictionary[key] = math.ceil((float(dictionary[key]) * range2) + x)

    return dictionary