#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX 101
int n, m;
int recommend[MAX];
int main(){
cin >> n >> m;
vector<pair<int, int>> students(n);
for (int i = 0; i < m; i++){
int pick;
cin >> pick;
recommend[pick]++;
bool check = true;
for (int j = 0; j < n; j++){
if (students[j].second == 0){
students[j].second = pick;
students[j].first = i;
check = false;
break;
}
else if (students[j].second == pick){
check = false;
break;
}
}
if (check){
int index = 0;
for (int j = 1; j < n; j++){
if (recommend[students[j].second] == recommend[students[index].second]){
if (students[j].first < students[index].first)
index = j;
}
else if (recommend[students[j].second] < recommend[students[index].second])
index = j;
}
recommend[students[index].second] = 0;
students[index].first = i;
students[index].second = pick;
}
}
vector<int> picture;
for (int i = 0; i < n; i++)
picture.push_back(students[i].second);
sort(picture.begin(), picture.end());
for (int i = 0; i < n; i++){
if (picture[i] == 0)
continue;
cout << picture[i] << " ";
}
return 0;
}
vector pair을 사용하여 (순서, 사진) 저장
가장 추천 수가 적거나 추천 수가 같으면 더 오래된 사진을 빼는 것을 구현
'스터디 > 알고리즘' 카테고리의 다른 글
[백준 2231] 분해합 (0) | 2022.02.11 |
---|---|
[백준 19532] 수학은 비대면강의입니다 (0) | 2022.02.11 |
[백준 5597] 과제 안 내신 분...? (0) | 2022.01.13 |
[백준 5212] 지구 온난화 (0) | 2022.01.13 |
[백준 2164] 카드2 (0) | 2022.01.10 |