可能答案
while True:
n, k = map(int, input().split())
food_stands = []
a = input().split()
for i in a:
food_stands.append(int(i))
back_up = "".join(str(e) for e in food_stands)
all_eat = 0
for eat in range(k):
slice_group = []
max = 0
while True:
slice = []
for food in food_stands:
if food in slice:
break
slice.append(food)
if len(slice) > max:
max = len(slice)
food_stands.pop(0)
slice_group.append(slice)
if len(food_stands) == 0:
break
all_eat += max
longgest = []
for slice in slice_group:
if len(slice) > len(longgest):
longgest = slice
longgest_str = "".join(str(e) for e in longgest)
back_up = back_up.replace(longgest_str, '')
if len(back_up) == 0:
break
food_stands = list(map(int, [char for char in back_up]))
print(all_eat)