# Untitled

unknown
plain_text
21 days ago
2.0 kB
1
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, processed_customers):
current_customer = -1
success_percentage = -1
highest_percentage = -1
current_offer = -1

for customer in range(n):
# 如果這個會員已經處理過了，則跳過
if customer in processed_customers:
continue

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

# 如果找到了最佳的優惠，就將該優惠從列表中減去一個
if current_offer != -1:
listK[current_offer] -= 1
# 將所有已處理過的會員標記為已處理

return current_customer, current_offer

final_list = [0] * n
customer_left = n
processed_customers = set()
while customer_left != 0:

value1, value2 = f(n, m, listK, percentage, processed_customers)
index_replace = value1
final_list[index_replace] = value2
customer_left -= 1

print(",".join(map(str, final_list)))
```