text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000007];
long long int freq[1000007];
int main() {
long long int n, i, flag = 0, maxi = -88, ans, index, curr;
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
maxi = max(maxi, arr[i]);
}
sort(arr, arr + n);
curr = 1;
for (i = 0; i < n; i++) {
if (arr[i] >= curr) curr++;
}
cout << curr;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
int ans = 2, i;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
for (i = 1; i < n; i++) {
if (arr[i] >= ans) ans++;
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> m;
int main() {
int n = 0;
cin >> n;
m.resize(n);
for (int i = 0; i < n; i++) {
cin >> m[i];
}
sort(m.begin(), m.begin() + n);
int j = 1;
for (int i = 0; i < n; i++) {
if (m[i] >= j) j++;
}
cout << j;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
int n;
scanf("%d", &n);
a.resize(n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
sort(a.begin(), a.end());
int mex = 1;
for (int i = 0; i < n; ++i)
if (a[i] >= mex) ++mex;
printf("%d", mex);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long int a[100010];
int main() {
long int i, j, k, n, mex;
scanf("%ld", &n);
for (i = 0; i < n; i++) scanf("%ld", &a[i]);
sort(a, a + n);
bool flag = 0;
mex = 1;
for (i = 0; i < n; i++) {
if (a[i] > mex) {
a[i] = mex++;
flag = 0;
} else if (mex == a[i] && ((i != 0 && a[i] != a[i - 1]) || i == 0)) {
mex++;
flag = 1;
}
}
printf("%ld", mex);
return 0;
}
|
#include <bits/stdc++.h>
using namespace ::std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
int n;
vector<int> v;
int main() {
cin >> n;
int z;
for (int i = 0; i < n; i++) {
scanf("%d ", &z);
v.push_back(z);
}
sort(begin(v), end(v));
int b = 1;
for (int i = 0; i < v.size(); i++) {
if (v[i] >= b) b++;
}
cout << b;
return 14 / 88;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
int mas[n];
for (int i = 0; i < n; i++) {
cin >> mas[i];
}
sort(mas, mas + n);
int cnt = 1;
for (int i = 0; i < n; i++) {
if (mas[i] >= cnt) cnt++;
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
int x[100010];
int main() {
int a, s = 1;
scanf("%d", &a);
for (int i = 1; i <= a; i++) scanf("%d", &x[i]);
std::sort(x + 1, x + a + 1);
for (int i = 1; i <= a; i++) {
if (x[i] >= s) s++;
}
printf("%d", s);
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65000000")
using namespace std;
int n;
int mas[100005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", mas + i);
sort(mas, mas + n);
int answ = 1;
int pos = 0;
while (pos < n) {
while (pos < n && mas[pos] < answ) ++pos;
if (pos < n) {
++answ;
++pos;
}
}
printf("%d\n", answ);
return 0;
}
|
#include <bits/stdc++.h>
int swap(int &a, int &b) {
int t;
t = a;
a = b;
b = t;
return 0;
}
int qsort(int *a, int l, int r) {
int i = l, j = r, x = a[(l + r) >> 1];
do {
while (a[i] < x) i++;
while (a[j] > x) j--;
if (i <= j) {
swap(a[i], a[j]);
i++;
j--;
}
} while (i <= j);
if (l < j) qsort(a, l, j);
if (i < r) qsort(a, i, r);
return 0;
}
int min(int a, int b) {
if (a <= b)
return a;
else
return b;
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int a[100005] = {0};
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
qsort(a, 1, n);
for (int i = 1; i <= n; i++) {
if (a[i] >= i)
a[i] = min(a[i - 1] + 1, i);
else if (a[i] < i)
a[i] = min(a[i], a[i - 1] + 1);
}
printf("%d\n", a[n] + 1);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, c;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
c = 1;
for (int i = 0; i < n; i++) {
if (a[i] == c)
c++;
else if (a[i] > c) {
a[i] = c;
c++;
}
}
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int mul(long long int x, long long int y) {
return (x * y) % 1000000007;
}
long long int power(long long int x, long long int y) {
long long int res = 1;
x %= 1000000007;
while (y) {
if (y & 1) res = mul(res, x);
y >>= 1;
x = mul(x, x);
}
return res;
}
long long int mod_inv(long long int x) { return power(x, 1000000007 - 2); }
long long int fact(long long int n) {
long long int res = 1;
for (long long int i = 2; i <= n; i++) res = mul(res, i);
return res;
}
long long int nCr(long long int n, long long int r) {
return mul(fact(n), mod_inv(mul(fact(r), fact(n - r))));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t = 1;
while (t--) {
long long int n;
cin >> n;
long long int a[n], i;
for (long long int index = 0; index < n; index++) cin >> a[index];
;
sort(a, a + n);
long long int x = 1;
for (i = 0; i < n; i++) {
if (a[i] >= x) x++;
}
cout << x << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int S = 100003;
const int MOD = 1000000007;
int _I() {
int x;
scanf("%d", &x);
return x;
}
long long _LL() {
long long x;
scanf("%lld", &x);
return x;
}
int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dirY[] = {0, 1, 0, -1, 1, -1, -1, 1};
int rX[] = {1, 1, 2, 2, -1, -1, -2, -2};
int rY[] = {2, -2, 1, -1, 2, -2, 1, -1};
int Set(int N, int pos) { return N = N | (1 << pos); }
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
map<int, int> M;
void Do() {
int n = _I(), x;
for (int i = 0; i < n; i++) M[x = _I()]++;
int last = 1, ans = 0, cn = 0;
for (int i = 1; i <= n; i++) {
if (!M[i]) {
ans++;
cn++;
} else {
int vvv = (M[i] - cn);
if (vvv < 0) {
cn = abs(vvv);
vvv = 0;
} else
cn = 0;
if (vvv == 0) {
cn++;
ans++;
}
ans += vvv;
}
if (ans >= n) {
ans = i + 1;
break;
}
}
cout << ans << endl;
}
int main() {
Do();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, x, y = 1;
cin >> n;
x = n + 1;
vector<long long> v(n);
for (int i = (0); i < (n); i++) cin >> v[i];
sort(v.begin(), v.end());
for (int i = (0); i < (n); i++) {
if (v[i] < y)
x--;
else
y++;
}
cout << x << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a[700007], b[700007];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int cur = 1;
for (int i = 0; i < n; i++) {
if (a[i] == cur) {
cur++;
} else if (a[i] > cur) {
cur++;
}
}
cout << cur << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
vector<int> graph[10007];
int mark[10007];
void bfs(int s) {
queue<int> q;
mark[s] = 1;
q.push(s);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = 0; i < graph[u].size(); i++) {
int h = graph[u][i];
if (mark[h] == 0) {
mark[h] = mark[u] + 1;
q.push(h);
}
}
}
}
int reverse(int x) {
int rev = 0;
while (x != 0) {
rev = rev * 10;
rev = rev + x % 10;
x = x / 10;
}
return rev;
}
void parz(int n, int m) {
vector<char> prime(m + 1, true);
prime[0] = prime[1] = false;
for (int i = n; i <= m; ++i)
if (prime[i])
if (i * 1ll * i <= m)
for (int j = i * i; j <= m; j += i) prime[j] = false;
for (int j = n; j <= m; j++) {
if (prime[j] == true) {
cout << j << endl;
}
}
for (int j = n; j <= m; j++) {
prime[j] = false;
}
}
long long isp(long long n) {
if (n <= 1) return 0;
if (n == 2) return 1;
if (n % 2 == 0) return 0;
for (long long i = 3; i * i <= n; i += 2)
if (n % i == 0) return 0;
return 1;
}
int tvan[10001];
struct on {
int x, y;
};
int poqraguyn(int a[], int n) {
int i, mn = 10000007;
for (i = 0; i < n; i++) {
if (a[i] < mn) {
mn = a[i];
}
}
return mn;
}
int a[100007];
bool row[100007];
bool col[100007];
int main() {
bool st[107];
long long t = 0, j;
long long k = 0, mx = 0, mxi = 0, mxi1 = 0;
bool o = true;
long long c = 0, it;
long long i = 0;
int i1 = 0, i2;
char s1[1007], s2[1007];
int N;
int jj = 0;
string s;
int n;
int ans = 1;
map<int, int> mp;
int m, x, y;
set<char> myset;
scanf("%d", &m);
for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
sort(a + 1, a + m + 1);
k = 1;
ans = 1;
for (int i = 1; i <= m; i++) {
if (a[i] < k) continue;
if (a[i] >= k) {
k++;
ans = k;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
void solve() {
long long n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
sort((v).begin(), (v).end());
long long mini = 1;
for (long long i = 0; i < n; i++) {
if (mini <= v[i]) {
mini++;
}
}
cout << mini;
}
int32_t main() {
long long t = 1;
while (t--) {
solve();
}
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
;
return 0;
}
|
#include <bits/stdc++.h>
template <typename T>
T power(T e, T n, T m) {
T x = 1, p = e;
while (n) {
if (n & 1) x = mod(x * p, m);
p = mod(p * p, m);
n >>= 1;
}
return x;
}
template <typename T>
T InverseEuler(T a, T m) {
return (a == 1 ? 1 : power(a, m - 2, m));
}
template <typename T>
T gcd(T a, T b) {
return __gcd(a, b);
}
template <typename T>
T lcm(T a, T b) {
return (a * (b / gcd(a, b)));
}
using namespace std;
const int MAX = 1005;
vector<long int> A;
int main() {
int N, i;
cin >> N;
A.resize(N);
for (i = 0; i < N; i++) cin >> A[i];
sort(A.begin(), A.end());
if (A[0] != 1) A[0] = 1;
for (i = 1; i < N; i++) {
if (A[i] - A[i - 1] > 1) {
A[i] = A[i - 1] + 1;
}
}
long int num;
bool flag = 0;
for (i = 1; i < N && !flag; i++) {
if (A[i] - A[i] > 1) {
num = A[i];
flag = 1;
}
}
if (flag == 1) {
cout << num - 1 << "\n";
} else {
cout << A[N - 1] + 1 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int b[a];
for (int i = 0; i < a; i++) {
cin >> b[i];
}
sort(b, b + a);
int dem = 1;
for (int i = 0; i < a; i++) {
if (b[i] >= dem) {
b[i] = dem;
dem++;
}
}
cout << dem;
}
|
#include <bits/stdc++.h>
const int INF_INT = 0x3f3f3f3f;
const long long INF_LL = 0x7f7f7f7f;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1);
using namespace std;
int n;
int a[100010];
int main(int argc, char const *argv[]) {
while (scanf("%d", &n) == 1) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
int ans = 1;
for (int i = 1; i <= n; i++) {
if (a[i] >= ans) {
ans++;
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, temp, mex = 1;
vector<long long int> a;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> temp;
a.push_back(temp);
}
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if (a[i] == mex)
mex++;
else if (a[i] > mex) {
a[i] = mex;
mex++;
} else
;
}
cout << mex << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[100005];
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int ans = 1;
for (int i = 0; i < n; i++)
if (a[i] >= ans) ans++;
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int ar[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t, i, j, k, n, m = 0, mx = 0, cnt = 0, flg = 0, sum = 0, mn = 1e10,
ans = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> ar[i];
sort(ar, ar + n);
for (i = 0; i < n; i++)
if (ar[i] > m) m++;
cout << m + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<long long, long long> pair1,
pair<long long, long long> pair2) {
return (pair1.first > pair2.first);
}
int main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
vector<long long> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
long long res = -1;
long long r = n + 1;
if (v[0] - 1 > n) {
res = v[0] - 1;
}
for (int i = 1; i < n; i++) {
if (i + 1 > v[i]) {
r = min(r, v[i] + n - i);
}
if (v[i] - v[i - 1] > n - i + 1) {
res = max(res, v[i] - (v[i] - v[i - 1] - n + i) + 1);
}
}
cout << (res > 1 ? r : r) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void merge(long long int a[], int p, int q, int r) {
int n, m;
n = q - p + 1;
m = r - q;
long long int l[n + 1], k[m + 1];
l[n + 1] = INT_MAX;
k[m + 1] = INT_MAX;
for (int i = 0; i < n; i++) {
l[i] = a[p + i];
}
for (int i = 0; i < m; i++) {
k[i] = a[q + i + 1];
}
int i = 0, j = 0, x = p;
while (i < n && j < m) {
if (l[i] <= k[j]) {
a[x] = l[i];
i++;
x++;
} else {
a[x] = k[j];
j++;
x++;
}
}
while (i < n) {
a[x] = l[i];
i++;
x++;
}
while (j < m) {
a[x] = k[j];
j++;
x++;
}
}
void merge_sort(long long int a[], int p, int r) {
int q;
if (p < r) {
q = (r + p) / 2;
merge_sort(a, p, q);
merge_sort(a, q + 1, r);
merge(a, p, q, r);
}
}
int main() {
int n, i;
cin >> n;
long long int array[n];
for (i = 0; i < n; i++) cin >> array[i];
merge_sort(array, 0, n - 1);
array[0] = 1;
i = 1;
while (i != n) {
if (array[i] - array[i - 1] > 1) array[i] = array[i - 1] + 1;
i++;
}
cout << array[n - 1] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long a[101000], n, k;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
k = 1;
for (int i = 1; i <= n; i++)
if (a[i] >= k) k++;
cout << k;
}
|
#include <bits/stdc++.h>
bool prime[5 * 100005];
void sieve(int64_t n) {
for (int64_t p = 2; p * p <= n; p++)
if (prime[p] == true)
for (int64_t i = p * p; i <= n; i += p) prime[i] = false;
prime[1] = false;
}
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int64_t tt = 1, t, n, m, w, i, j, k, a, b, x, y, ans = 1, sum = 0, cnt = 0;
while (tt--) {
int64_t q;
cin >> n;
int64_t a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
k = 1;
a[0] = 1;
for (i = 1; i < n; i++) {
if (a[i] >= a[i - 1] + 1) {
a[i] = a[i - 1] + 1;
}
}
cout << a[n - 1] + 1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
a[0] = 1;
for (int i = 0; i < n; i++) {
if (a[i + 1] > a[i]) {
a[i + 1] = a[i] + 1;
}
}
printf("%d", a[n - 1] + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000009;
const double eps = 1e-9;
const int mod = 1000000007;
int nos[100001], n, pos = 0;
int main() {
cin >> n;
for (int i = 0; i < n; ++i) scanf("%d", &nos[i]);
sort(nos, nos + n);
for (int i = 0; i < n; ++i)
if (pos + 1 <= nos[i]) ++pos;
printf("%d\n", pos + 1);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int i, c = 0, a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (i = 0; i < n; i++) {
if (c < a[i]) c++;
}
cout << c + 1;
}
|
#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
int n;
std::cin >> n;
std::vector<int> data(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &data[i]);
}
std::sort(data.begin(), data.end(), std::greater<int>());
int ans = data.size() + 1;
int k = 1;
for (int i = 0; i < n && k < data.size(); ++i) {
while (data[i] < ans - k) --ans;
++k;
}
std::cout << ans << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6, PI = acos(-1);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n, a[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
sort(a, a + n);
int ans = 1;
for (int i = 0; i < n; ++i)
if (a[i] >= ans) ans++;
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
long long int a[100010];
int main() {
long long int x, y, i, j, k, count = 0, sum = 0, m = 0, n = 0;
scanf("%I64d", &x);
for (i = 0; i < x; i++) scanf("%I64d", &a[i]);
std::sort(a, a + x);
a[0] = 1;
for (i = 1; i < x; i++) {
if (a[i] - a[i - 1] > 2) {
count += (a[i] - a[i - 1] - 1);
n = a[i - 1];
m = i;
} else if (a[i] - a[i - 1] == 2)
a[i] -= 1;
if (count > 0) {
a[i] = n + 1;
count = 0;
n = a[i];
}
}
if (count == 0)
printf("%I64d", a[x - 1] + 1);
else
printf("%I64d", a[m] - 1);
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int mexActual = 1;
for (int i = 0; i < n; i++) {
if (mexActual <= a[i]) mexActual++;
}
cout << mexActual << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
int a[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
sort(a, a + n);
int ans = 1;
for (int i = 0; i < n; ++i) {
if (a[i] >= ans) ans++;
}
printf("%d\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int skaiciai[100005];
for (int i = 0; i < n; i++) {
cin >> skaiciai[i];
}
sort(skaiciai, skaiciai + n);
int ats = 1;
for (int i = 0; i < n; i++) {
if (skaiciai[i] >= ats) {
ats++;
}
}
cout << ats;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
long long POWER(long long x, long long y, long long m) {
if (y == 0) return 1;
if (y % 2 == 0) {
long long temp = POWER(x, y / 2, m);
temp *= temp;
temp %= m;
return temp;
}
long long temp = POWER(x, y - 1, m);
temp *= x;
temp %= m;
return temp;
}
long long POWER(long long x, long long y) {
if (y == 0) return 1;
if (y % 2 == 0) {
long long temp = POWER(x, y / 2);
temp *= temp;
return temp;
}
long long temp = POWER(x, y - 1);
temp *= x;
return temp;
}
int a[100010];
int main() {
ifstream fin("ali");
int n, cnt = 0;
cin >> n;
set<int> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int MIN = 1;
for (int i = 0; i < n; i++) {
if (a[i] >= MIN) {
MIN++;
continue;
}
}
cout << MIN << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, ff = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') ff = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * ff;
}
int N;
int a[100010];
int main() {
N = read();
for (int i = 1; i <= N; i++) a[i] = read();
sort(a + 1, a + 1 + N);
int k = 1;
for (int i = 1; i <= 100010; i++) {
while (a[k] < i && k <= N) k++;
if (k > N) {
printf("%d\n", i);
return 0;
}
k++;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int X = 100000 + 5;
void MAIN() {
long long n, x, m;
cin >> n;
m = n;
vector<int> v;
while (n--) {
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
n = 1;
for (int i = 0; i < (int)v.size(); i++) {
if (v[i] >= n) {
n++;
}
}
cout << n;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(12);
MAIN();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, i, j, n;
cin >> n;
long long a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
long long c = 1;
for (i = 0; i < n; i++) {
if (a[i] > c) {
a[i] = c;
c++;
} else if (a[i] == c) {
c++;
}
}
cout << a[n - 1] + 1;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr.begin(), arr.end());
int r = -1;
int find = 1;
for (int i = 0; i < n; i++) {
if (arr[i] < find) {
} else {
find++;
}
r = find;
}
cout << r;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[100001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
int counter = 1;
for (int i = 0; i < n; i++) {
if (i == 0) {
if (arr[i] >= counter) {
arr[i] = counter;
counter++;
}
}
if (i > 0) {
if (arr[i] >= counter && arr[i - 1] != arr[i]) {
arr[i] = counter;
counter++;
}
}
}
cout << counter;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 5;
const int inf = 1e9;
const long long OO = 1e18;
const long long MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
int last = 0;
for (int i = 0; i < n; i++) v[i] = v[i] > last ? last + 1 : v[i], last = v[i];
cout << v[n - 1] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long a, long long b, long long mod) {
a %= mod;
if (a < 0) a += mod;
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
while (b) {
long long temp = a;
a = b;
b = temp % b;
}
return a;
}
int a[100005];
int main() {
std::ios::sync_with_stdio(false);
int i, j, n;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int mex = -1;
mex = 1;
for (i = 1; i < n; i++) {
if (a[i] == mex) {
continue;
} else {
mex++;
}
}
cout << mex + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n;
cin >> n;
long long int i, a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int ma = 0;
for (i = 0; i < n; i++) {
if (a[i] > ma + 1) {
a[i] = ma + 1;
}
ma = max(ma, a[i]);
}
cout << a[i - 1] + 1;
}
|
#include <bits/stdc++.h>
using namespace std;
int num[100011];
int n;
int main() {
memset(num, 0, sizeof(num[0]));
scanf("%d", &n);
int i;
for (i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (x > n) x = n + 1;
num[x]++;
}
int left, con, m;
left = 0;
con = 0;
for (i = 1; i <= n + 1; i++) {
if (num[i] != 0 && left == 0) con++;
if (left != 0) {
m = min(left, num[i]);
con += m;
left = left - m;
num[i] -= m;
}
if (num[i] == 0) left++;
if (left == 0)
if (num[i] == 0)
con = i - 1;
else
con = i;
}
printf("%d\n", con + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
int mex = 1;
for (int i = 0; i < n; i++) {
if (arr[i] >= (mex)) {
mex++;
continue;
}
}
cout << mex;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int N = 100001;
int n, a[N];
int ans;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; (i) < (n); ++i) cin >> a[i];
sort(a, a + n);
int c = 1;
for (int i = 0; i < n; i++) {
if (a[i] >= c) {
c++;
}
}
cout << c << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 10;
int ary[N];
int val[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ary[i];
val[min(ary[i], N - 1)]++;
}
int sum = 0;
for (int i = 1; i < N; i++) {
if (val[i] == 0) {
sum++;
} else {
sum = max(0, sum - val[i] + 1);
}
}
cout << N - sum << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64777215")
using namespace std;
const long long maxn = 200001;
const long long maxq = 1000001;
const long long mo = 5;
const long long maxseg = 262144;
const long long secret_number = -87468267;
const pair<int, int> secret_pair = make_pair(secret_number, secret_number);
const long long inf = 1e18;
const long long mod = 87178291199;
const int iinf = 2147483647 / 2;
const double pi = 3.141592653589793238462643383279502884;
const double eps = 1e-7;
const string something_very_long =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaa";
const string govno = "g";
int main() {
int n;
int x;
int free = 0;
int count = 0;
map<int, int> a;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x;
a[x]++;
}
for (int i = 1; i < n + 1; ++i)
if (a.find(i) == a.end()) a[i] = 0;
for (int i = 1; i < maxn; ++i) {
free -= a[i] - 1;
free = max(0, free);
count += a[i];
if (n - count <= free) {
int fil = n - count;
cout << i - free + fil + 1;
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int a[maxn];
int main() {
int n;
while (cin >> n) {
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
int mi = 1;
for (int i = 0; i < n; ++i) {
if (a[i] >= mi) mi++;
}
cout << mi << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll inf = (ll)1e18 + 1;
const ll mod = 1000000007;
const db PI = 3.141592653589793238;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vl v(n), a(n);
for (auto &i : v) cin >> i;
sort(begin(v), end(v));
unordered_map<ll, ll> ump;
for (int i = 0; i < n; i++) {
a[i] = i + 1;
}
int k = 0;
for (int i = 0; i < n; i++) {
if (v[i] >= a[k]) {
v[i] = a[k];
k++;
}
ump[v[i]]++;
}
for (int i = 1; i < n + 2; i++) {
if (!ump.count(i)) {
cout << i;
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
vector<bool> visited;
vector<int> topologicalSort;
int dfs(int node) {
visited[node] = 1;
for (int i = 0; i < adj[node].size(); i++) {
if (!visited[adj[node][i]]) dfs(adj[node][i]);
}
}
int main() {
int n;
cin >> n;
long long a[100001];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
if (a[0] > 1) a[0] = 1;
for (int i = 0; i < n - 1; i++) {
if (a[i + 1] - a[i] > 1) a[i + 1] = a[i] + 1;
}
cout << a[n - 1] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, m = 0;
cin >> n;
vector<long long> v;
int a[100001];
fill(a, a + 100001, 0);
for (int i = 0; i < n; i++) {
cin >> x;
if (x > 100000) x = 100000;
a[x]++;
}
for (int i = 1; i <= n; i++) {
if (a[i] == 0) {
a[i]++;
m++;
} else if (a[i] > 1) {
while (m > 0 && a[i] > 1) {
m--;
a[i]--;
}
}
}
for (int i = 1; i <= n; i++) {
for (int x = 0; x < a[i]; x++) {
v.push_back(i);
if (v.size() == n) break;
}
if (v.size() == n) break;
}
cout << *max_element(v.begin(), v.end()) + 1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int crnt = 1;
vector<int> arr(n);
for (auto &i : arr) cin >> i;
sort(arr.begin(), arr.end());
for (int i = 0; i < n; i += 1)
if (arr[i] >= crnt) crnt++;
cout << crnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n1, long long n2) {
if (n1 % n2 == 0) return n2;
return gcd(n2, n1 % n2);
}
long long powmod(long long base, long long exponent) {
long long ans = 1;
while (exponent) {
if (exponent & 1) ans = (ans * base) % 1000000007;
base = (base * base) % 1000000007;
exponent /= 2;
}
return ans;
}
int arr[100005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
int curr = 1;
for (int i = 0; i < n; i++) {
if (arr[i] >= curr) curr++;
}
cout << curr << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const int MAX = 10000000;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
while (cin >> n) {
int mex = 1;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
if (v[i] >= mex) mex++;
}
cout << mex << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int a[maxn];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int maxx = 0;
for (int i = 0; i < n; ++i) {
if (maxx < a[i]) maxx++;
}
cout << maxx + 1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, a[101001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
long long ans = 1;
for (int i = 1; i <= n; ++i)
if (a[i] >= ans) ans++;
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int mas[100001];
int main() {
int n, m;
int i, j;
cin >> n;
for (i = 0; i < n; i++) cin >> mas[i];
int ans = 1;
sort(mas, mas + n);
for (i = 0; i < n; i++)
if (ans <= mas[i]) ans++;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
if (n == 1) {
cout << 2;
return 0;
}
if (n == 2) {
if (v[1] == 1) {
cout << 2;
} else {
cout << 3;
}
return 0;
}
int k = 2;
v[0] = 1;
int index = 1;
while (index < n - 1) {
if (v[index] == k - 1) {
index++;
continue;
}
long long up = upper_bound(v.begin() + index, v.end(), k) - v.begin();
long long low = lower_bound(v.begin() + index, v.end(), k) - v.begin();
if (up != low) {
k++;
index++;
continue;
}
v[index] = k;
k++;
index++;
}
if (v[n - 1] > v[n - 2]) {
v[n - 1] = v[n - 2] + 1;
}
cout << v[n - 1] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
for (int _n(n), i(0); i < _n; i++) cin >> a[i];
sort((a).begin(), (a).end());
int ans = 1;
for (int x : a) {
if (x >= ans) ++ans;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
long long a[n + 1];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (a[0] > n)
cout << n + 1;
else {
int temp = a[0];
for (i = 0; i < a[0] - 1; i++) {
a[i + 1] = i + 1;
}
i = a[0];
while (i < n) {
if (a[i] > temp + 1) a[i] = temp + 1;
temp = a[i];
i++;
}
sort(a, a + n);
cout << a[n - 1] + 1;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, cur = 1;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; ++i) {
if (a[i] >= cur) {
cur++;
}
}
cout << cur;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, k;
long long n, m;
cin >> n;
long long a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long x = 1;
for (i = 0; i < n; i++) {
if (a[i] == x)
x++;
else if (x < a[i]) {
a[i] = x;
x++;
}
}
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[100009];
long long i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a, a + n + 1);
a[1] = 1;
for (i = 2; i <= n; i++) {
if (a[i] - a[i - 1] >= 2) a[i] = a[i - 1] + 1;
}
cout << a[n] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma warning(disable : 6031)
void IO() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
const int N = (int)1e5 + 5;
int a[N];
int main() {
IO();
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a, a + n + 1);
int cnt = 1;
for (int i = 1; i <= n; i++)
if (a[i] >= cnt) cnt++;
cout << cnt;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 10;
int n, j = 1, a[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
sort(a, a + n);
for (int i = 0; i < n; ++i) {
if (a[i] < j) {
continue;
}
j++;
}
printf("%d\n", j);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void write(T x) {
int i = 20;
char buf[21];
buf[20] = '\n';
do {
buf[--i] = x % 10 + '0';
x /= 10;
} while (x);
do {
putchar(buf[i]);
} while (buf[i++] != '\n');
}
template <typename T>
inline T readInt() {
T n = 0, s = 1;
char p = getchar();
if (p == '-') s = -1;
while ((p < '0' || p > '9') && p != EOF && p != '-') p = getchar();
if (p == '-') s = -1, p = getchar();
while (p >= '0' && p <= '9') {
n = (n << 3) + (n << 1) + (p - '0');
p = getchar();
}
return n * s;
}
int main() {
long long n = readInt<long long>();
long long a[n];
for (int i = 0; i < n; i++) a[i] = readInt<long long>();
sort(a, a + n);
long long cur_mex = 1;
for (int i = 0; i < n; i++) {
if (a[i] >= cur_mex) {
cur_mex++;
}
}
cout << cur_mex;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> x(n);
for (__typeof(n) i = 0; i != n; i += 1) {
cin >> x[i];
}
sort(x.begin(), x.end());
int cur = 1;
for (__typeof(n) i = 0; i != n; i += 1) {
if (x[i] >= cur) {
cur++;
}
}
cout << cur;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
int p = 1;
for (int i = 1; i <= n; i++) {
if (a[i] >= p) p++;
}
cout << p;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
vector<int> elements(t);
while (t--) cin >> elements[t];
sort(elements.begin(), elements.end());
t = elements.size() - 1;
elements[0] = 1;
for (int i = 0; i < t; i++) {
if (elements[i + 1] > elements[i]) elements[i + 1] = elements[i] + 1;
}
cout << elements.back() + 1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[300000];
int main() {
long int n;
cin >> n;
for (long int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
priority_queue<long long int> pq;
pq.push(1);
a[1] = 1;
for (long int i = 2; i <= n; i++) {
if (a[i] == a[i - 1] && a[i] < i) {
;
} else {
a[i] = a[i - 1] + 1;
}
}
cout << a[n] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a[100002], nw = 1;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
for (int i = 0; i < n; i++)
if (nw <= a[i]) a[i] = nw++;
printf("%d\n", nw);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int oo = 2147483647;
const int maxN = (int)1e5 + 1;
int N, a[maxN], b[maxN], c[maxN];
bool d[maxN];
void enter() {
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
}
void process() {
sort(a + 1, a + N + 1);
a[1] = 1;
for (int i = 2; i <= N; i++)
if (a[i] - a[i - 1] > 1) a[i] = a[i - 1] + 1;
cout << a[N] + 1 << endl;
}
int main() {
std ::ios_base::sync_with_stdio(false);
cin.tie(NULL);
enter();
process();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
register int i;
cin >> n;
long int a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
a[0] = 1;
for (i = 0; i < n; i++) {
if (a[i + 1] - a[i] > 1) {
a[i + 1] = a[i] + 1;
}
}
cout << a[n - 1] + 1;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j = 1;
cin >> n;
vector<long long> v(n);
for (i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
for (i = 0; i < v.size(); i++) {
if (v[i] >= j) {
v[i] = j;
j++;
} else
continue;
}
cout << v[v.size() - 1] + 1;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int cnt = 1;
for (long long int i = 0; i < n; i++) {
if (a[i] >= cnt) cnt++;
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200050;
int n, A[maxn];
int main() {
scanf("%d", &n);
for (int i = 0; i < (int)(n); i++) {
scanf("%d", &A[i]);
}
sort(A, A + n);
int add = 1;
for (int i = 0; i < (int)(n); i++) {
if (A[i] >= add) {
add++;
}
}
printf("%d\n", add);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, i;
int k;
cin >> k;
long long v[k + 1];
for (i = 1; i <= k; i++) {
cin >> v[i];
}
sort(v + 1, v + k + 1);
v[1] = 1;
for (i = 1; i < k; i++) {
if (v[i] + 1 < v[i + 1]) v[i + 1] = v[i] + 1;
}
cout << v[k] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, ar[100001];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
sort(ar, ar + n);
int cur = 1;
for (int i = 0; i < n; i++) {
if (ar[i] >= cur) cur++;
}
cout << cur << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int cnt = 1;
sort(a, a + n);
for (int i = 0; i < n; i++)
if (a[i] >= cnt) a[i] = cnt, cnt++;
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int simpleSieve(long long int limit, vector<long long int> &prime) {
long long int c = 0;
vector<bool> mark(limit + 1, true);
for (long long int p = 2; p * p < limit; p++) {
if (mark[p] == true) {
for (long long int i = p * p; i < limit; i += p) mark[i] = false;
}
}
for (long long int p = 2; p < limit; p++) {
if (mark[p] == true) {
prime.push_back(p);
c++;
}
}
return c;
}
long long int segmentedSieve(long long int n) {
long long int limit = floor(sqrt(n)) + 1;
vector<long long int> prime;
prime.reserve(limit);
int c = simpleSieve(limit, prime);
long long int low = limit;
long long int high = 2 * limit;
while (low < n) {
if (high >= n) high = n;
bool mark[limit + 1];
memset(mark, true, sizeof(mark));
for (long long int i = 0; i < prime.size(); i++) {
int loLim = floor(low / prime[i]) * prime[i];
if (loLim < low) loLim += prime[i];
for (long long int j = loLim; j < high; j += prime[i])
mark[j - low] = false;
}
for (long long int i = low; i < high; i++)
if (mark[i - low] == true) c++;
low = low + limit;
high = high + limit;
}
return c;
}
long long int min(long long int a, long long int b) {
return ((a < b) ? a : b);
}
int main() {
long long int n, s = 0, b, f = 0, i = 0, t, a, w, h, j = 0, p, q, m;
long long int brr[100000];
unordered_map<int, int> freq;
string str, str2;
vector<pair<long long int, long long int>> v1;
priority_queue<long long int, vector<long long int>, greater<long long int>>
pq;
int64_t c = 1;
cin >> n;
long long int arr[n];
for (i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
for (i = 0; i < n; i++) {
if (arr[i] >= c) c++;
}
cout << c;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100008];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
a[0] == 1;
sort(a, a + n + 1);
for (int i = 1; i <= n; i++) {
if (a[i] == a[i - 1])
continue;
else
a[i] = a[i - 1] + 1;
}
printf("%d", a[n] + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005];
int main() {
std::ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
stable_sort(a, a + n);
int k = 1;
for (int i = 1; i < n; i++) {
if (a[i] > k) {
k += 1;
a[i] = k;
}
}
cout << k + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int p1, p2, n, element, result, ma, gap, carry;
cin >> n;
map<int, int> mp1;
map<int, int>::iterator it, p_it;
ma = 0;
for (p1 = 0; p1 < n; p1++) {
cin >> element;
mp1[element]++;
ma = max(ma, element);
}
mp1[0]++;
it = mp1.end();
it--;
result = ma + 1;
carry = 0;
for (; it != mp1.begin(); it--) {
p_it = it;
p_it--;
gap = it->first - p_it->first;
carry += it->second;
if (carry >= gap)
carry -= gap;
else {
result -= (gap - carry);
carry = 0;
}
}
cout << result;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
long long ans = 0;
sort(a, a + n);
for (long long i = 0; i < n; i++)
if (a[i] > ans) ans++;
ans++;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j;
int a[100010];
int main() {
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
int ans = 1;
j = 0;
while (j < n) {
if (a[j] >= ans) {
ans++;
}
j++;
}
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
cin >> n;
int a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int x = 1;
for (i = 0; i < n; i++) {
if (a[i] >= x) {
a[i] = x;
x++;
}
}
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int ans = 1;
for (int i = 0; i < n; i++) {
if (ans <= a[i]) {
ans++;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
multiset<int> st;
for (int i = 0; i < n; i++) {
cin >> a[i];
st.insert(a[i]);
}
sort(a.begin(), a.end());
int x = 1;
while (true) {
auto it = a.begin();
bool flag = 0;
for (it = a.begin(); it != a.end(); it++) {
if (*it >= x) {
flag = 1;
a.erase(it);
x++;
break;
}
}
if (flag == 0) {
cout << x;
return;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[100005];
int n, ans = 1;
scanf(" %d", &n);
for (int i = 0; i < n; i++) scanf(" %d", &a[i]);
sort(a, a + n);
for (int i = 0; i < n; i++)
if (a[i] >= ans) ans++;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long ans = 1;
for (long long i = 0; i < n; i++) {
if (a[i] > ans) {
a[i] = ans;
ans = a[i] + 1;
} else if (a[i] == ans) {
ans = a[i] + 1;
}
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100001];
int main() {
long long n;
cin >> n;
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
a[0] = 1;
for (long long i = 1; i < n; i++) a[i] = min(a[i], a[i - 1] + 1);
cout << a[n - 1] + 1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long arr[100001];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
long long j = 1;
for (int i = 0; i < n; i++) {
if (arr[i] > j) {
arr[i] = j;
j++;
} else if (arr[i] == j)
j++;
}
cout << j << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int a[100009] = {0};
int main() {
int i, j, k;
i = 0;
int n;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int b[100009];
i = 0;
b[1] = 1;
j = 1;
for (i = 1; i < n; i++) {
if (a[i] > j) j++;
}
printf("%d\n", j + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
}
int sum(int a, int b) {
add(a, b);
return a;
}
int mult(int a, int b) { return (1ll * a * b) % mod; }
int n, a[N], dp[N];
int main() {
ios_base::sync_with_stdio(0);
clock_t start = clock();
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
dp[0] = 1;
for (int i = 1; i <= n; i++) {
if (a[i] >= dp[i - 1])
dp[i] = dp[i - 1] + 1;
else
dp[i] = dp[i - 1];
}
cout << dp[n] << endl;
double duration = ((double)clock() - start) / (double)CLOCKS_PER_SEC;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i, p = 1;
cin >> n;
int ara[n];
for (i = 0; i < n; i++) cin >> ara[i];
sort(ara, ara + n);
for (i = 0; i < n; i++) {
if (ara[i] >= p) p++;
}
cout << p;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void check() {
int n;
cin >> n;
vector<int> a(n);
long long curr = 1;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
for (int i = 0; i < n; ++i) {
if (curr <= a[i]) curr++;
}
cout << curr << "\n";
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
long long t;
t = 1LL;
while (t--) {
check();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long Mod(long long b, long long p, long long m) {
if (p == 0) return 1;
long long ans = Mod(b, p / 2, m);
ans = (ans * ans) % m;
if (p % 2 == 1) ans = (ans * b) % m;
return ans;
}
int sz = 75;
void sieve(vector<int>& v) {
v.assign(sz, 0);
v[0] = 1;
v[1] = 1;
for (int i = 4; i <= sz; i += 2) v[i] = 1;
for (int i = 3; i * i <= sz; i += 2) {
if (v[i] == 0) {
for (int j = i * i; j <= sz; j += i * 2) {
v[j] = 1;
}
}
}
}
long long Pow(long long b, long long p) {
long long ans = 1;
for (long long i = 1; i <= p; i++) {
ans *= b;
}
return ans;
}
void solve() {
long long n;
std::vector<long long> v;
cin >> n;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end());
long long cont = 1;
for (long long i = 0; i < n; i++) {
if (v[i] >= cont) cont++;
}
cout << cont << endl;
}
int main() {
solve();
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.