[ North American Invitational Programming Contest 2018 ] Missing Gnomes

#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,m,a[N],b[N],c[N],cnt;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d",&a[i]),b[a[i]]=1;
    a[m+1]=n+1;
    int pos=1;
    for(int i=1;i<=n+1;i++)
    if(!b[i]){
        while(a[pos]<i){
            c[++cnt]=a[pos++];
        }
        c[++cnt]=i;
    }
    for(int i=1;i<=n;i++) printf("%d\n",c[i]);
}

Leave a Reply

Your email address will not be published.