from structs.landmark import Landmark

def take_most_important(landmarks: list[Landmark], N_important) -> list[Landmark] :
    L = len(landmarks)
    L_copy = []
    L_clean = []
    scores = [0]*len(landmarks)
    names = []
    name_id = {}

    for i, elem in enumerate(landmarks) :
        if elem.name not in names :
            names.append(elem.name)
            name_id[elem.name] = [i]
            L_copy.append(elem)
        else :
            name_id[elem.name] += [i]
            scores = []
            for j in name_id[elem.name] :
                scores.append(L[j].attractiveness)
            best_id = max(range(len(scores)), key=scores.__getitem__)
            t = name_id[elem.name][best_id]
            if t == i :
                for old in L_copy :
                    if old.name == elem.name :
                        old.attractiveness = L[t].attractiveness
    
    scores = [0]*len(L_copy)
    for i, elem in enumerate(L_copy) :
        scores[i] = elem.attractiveness

    res = sorted(range(len(scores)), key = lambda sub: scores[sub])[-(N_important-L):]

    for i, elem in enumerate(L_copy) :
        if i in res :
            L_clean.append(elem)

    return L_clean
