-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path445.cpp
67 lines (59 loc) · 1.16 KB
/
445.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int arr[1000005];
set<int> av;
int main()
{
int k;
long long n;
scanf("%d%lld",&k,&n);
queue<int> data;
set<int>::iterator it=av.begin();
int a;
for(int i=0;i<k;i++)
{
scanf("%d",&a);
data.push(a);
//av.erase(a);
if(a<1000005) arr[a]++;
}
for(int i=1;i<1000005;i++)
{
if(arr[i]==0)
av.insert(i);
}
int brr[k+1];
for(int i=0;i<k;i++)
{
int f=-1;
f=(int)*av.begin();
data.push(f);
av.erase(f);
arr[f]++;
//cout<<"i add "<<f<<endl;
if(data.front()<1000005)
{
arr[data.front()]--;
if(arr[data.front()]==0) av.insert(data.front());
}
//cout<<"i pop "<<data.front()<<endl;
data.pop();
brr[i]=f;
}
int f=-1;
f=(int)*av.begin();
data.push(f);
arr[f]++;
brr[k]=f;
long long j=n-k-1;
j=j%(k+1);
cout<<brr[j]<<endl;
/*for(int i=0;i<j-1;i++)
{
//cout<<data.front()<<" ";
data.pop();
}
cout<<data.front()<<endl;*/
return 0;
}