https://www.acmicpc.net/problem/1700
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#pragma warning(disable: 4996)
using namespace std;
const int INF = 987654321;
int n, k;
bool cmp(pair<char, int> a, pair<char, int> b){
return a.second> b.second;
}
int findIdx(string s, int i){
int ret=0;
int idx = s.find(s.at(i), i+1);
if(idx == -1)
ret = INF;
else
ret = idx;
return ret;
}
int main(){
scanf("%d %d", &n, &k);
map<char, int> m;
string s = "";
int c;
for(int i=0;i<k;i++){
scanf("%d", &c);
s += '0'+c;
}
int answer = 0;
for(int i=0;i<k;i++){
if(m.find(s[i]) != m.end()){ // 찾음
m[s[i]]= findIdx(s, i);
}else{ // 못찾음
if(m.size() == n){
vector<pair<char, int>> vec(m.begin(), m.end());
sort(vec.begin(), vec.end(), cmp);
m.erase(vec[0].first);
answer++;
}
m.insert(make_pair(s[i], findIdx(s, i)));
}
}
cout<<answer<<endl;
return 0;
}
#include<stdio.h>
int n, k;
int u[102], o[102];
int us=0;
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < k; i++) scanf("%d", &o[i]);
int cnt = 0;
for (int i = 0; i < k; i++) {
int j;
for (j = 0; j < us; j++) {
if (u[j] == o[i]) break;
}
if (j == n) {
int maxi = 0,midx;
int p;
for (j = 0; j < us; j++) {
for (p = i + 1; p < k &&o[p] != u[j]; p++);
if (p > maxi) maxi = p, midx = j;
}
u[midx] = o[i];
cnt++;
}
else if (j == us) u[us++] = o[i];
}
printf("%d", cnt);
return 0;
}