Untitled

mail@pastecode.io avatar
unknown
python
16 days ago
1.5 kB
4
Indexable
Never
strnm = input()
listnm = [int(g) for g in (strnm.split(','))]
n = listnm[0]
m = listnm[1]

percentage = []
customer_numb = 0
while customer_numb < n:
    each_percentage_str = input()
    each_percentage_list = [int(g) for g in (each_percentage_str.split(','))]
    percentage.append(each_percentage_list)
    customer_numb += 1

strK = input()
listK = [int(g) for g in (strK.split(","))]
listK.insert(0, n)

def f(n, m, listK, percentage):
    current_customer = -1
    success_percentage = -1
    highest_percentage = -1
    current_offer = -1

    for customer in range(n):
        for offer in range(m + 1):
            if listK[offer] > 0:
                success_percentage = percentage[customer][offer]
                if success_percentage > highest_percentage or (success_percentage == highest_percentage and listK[offer] > listK[current_offer]) or (success_percentage == highest_percentage and listK[offer] == listK[current_offer] and offer < current_offer):
                    highest_percentage = success_percentage
                    current_customer = customer
                    current_offer = offer
                    listK[offer] -= 1

    return current_customer, current_offer

final_list = [0] * n
customer_left = n
while customer_left != 0:
    value1, value2 = f(n, m, listK, percentage)
    index_replace = value1
    final_list[index_replace] = value2
    customer_left -= 1

print(",".join(map(str, final_list)))
Leave a Comment