Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define all(x) x.begin(), x.end()
- int mex(vector<int> a) {
- int n = a.size();
- sort(all(a));
- if (a[0] > 0) {
- return 0;
- }
- for (int i = 0; i < n - 1; ++i){
- if (a[i] + 1 < a[i + 1]){
- return a[i] + 1;
- }
- }
- return a.back() + 1;
- }
- int main() {
- int n;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; ++i){
- cin >> a[i];
- }
- cout << mex(a) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement