https://www.acmicpc.net/problem/2910

처음에 몇 번 나왔는지 세기 위해서 딕셔너리를 쓸까 생각했다가 등장 횟수가 같을 때 정렬하기가 효율적이지 않을 것 같아서 리스트로 방향을 틀었다.
saved라는 리스트에 [value, cnt, idx]를 넣고 cnt로 내림차순 정렬한 후 idx로 오름차순 정렬해주었다. 이렇게 해야 문제에서 원하는, 등장하는 횟수가 같다면 먼저 나온 것이 앞에 있어야 한다라는 규칙을 지킬 수 있다.
saved.sort(key= lambda x:(-x[1], x[2]))
파이썬 내장함수 중 any()와 all()을 알게 되었다.
any() : 하나라도 True인게 있으면 True
all() : 모두 True여야 True
if any(arr[0] == l[i] for arr in saved):
arr[0] == l[i]가 하나라도 존재하면 True 반환
if all(arr[0] == l[i] for arr in saved):
모든 arr[0]이 l[i]와 같다면 True 반환
n, c = map(int, input().split())
l = list(map(int, input().split()))
saved = []
for i in range(n):
if any(arr[0] == l[i] for arr in saved): continue # 이미 saved 내 value로 있으면 continue
saved.append((l[i], l.count(l[i]), i)) # value, cnt, idx
saved.sort(key= lambda x:(-x[1], x[2])) # cnt 내림차순 정렬 후, idx 오름차순 정렬
for i in range(len(saved)):
a, b = saved[i][0], saved[i][1]
for j in range(b):
print(a, end=" ")
똑똑이~