Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, k, m=1;
- int tab[1000009];
- cin>>n>>k;
- for (int i=0; i<n; ++i) cin>>tab[i];
- sort(tab, tab+n);
- for (int i=0; i<n; ++i){
- if(tab[i]!=m&&m%k==0) break;
- else if (tab[i]!=m&&m%k!=0) {i--;m++;}
- else m++;
- }
- cout<<m;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement