C - 最大墨西哥 (atcoder.jp)
给定n个数,从中选m个数,找到m个数中其中没出现的最小的数
#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b;i ++ )
#define fd(i,a,b) for(int i=a;i>=b;i -- )
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL;
typedef vector<vector<LL>> VVL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N = 3e5+ 10,M = N *4 ,INF = 0x3f3f3f3f ;
const int mod = 1e9;
const double eps = 1e-8;
int a[N],q[N];
bool st[INF];
int hh =0,tt=0;
inline void solve()
{
int n,m;cin >> n >> m;
vector<int> cnt(n + 1 );
fu(i,0,n-1)
{
int x;cin >> x;
if(x <= n)
cnt[x] ++ ;
}
int ans =0 ;
while(ans < m && cnt[ans] > 0 ) ans ++;
cout << ans <<endl;
}
signed main()
{
// freopen("1.txt","w",stdout);
ios
int t=1;
// cin>>t;
int now = 1;
while(t -- )
{
// cout<<"Case ";
// cout<<"Scenario #";
// cout<< now ++ <<": ";
// cout<< now ++ <<": \n";
solve();
}
return 0;
}