/* _ _ ___ __ ___ ___ _ _ ___ __ ___ _ _ ___ ___ __ _____ _ _ ___ */
/* | || | /_\ \ / / / __|/ _ \| \| |/ __| \ \ / /_\ | | | |/ _ \ / __| \ \ / / _ \| \| |/ __| */
/* | __ |/ _ \ V / \__ \ (_) | .` | (_ | \ V / _ \ | |_| | (_) | (__ \ V / (_) | .` | (_ | */
/* |_||_/_/_\_\_|___|___/\___/|_|\_|\___| \_/_/_\_\ _\___/ \___/ \___| _ \_/_\___/|_|\_|\___| ___ */
/* | \| __| |_ _| || | /_\ \ / / | \ / _ \_ _| | \/ | __| \| | || | | \/ |/ _ \| \| |/ __| */
/* | |) | _| | | | __ |/ _ \ V / | |) | (_) | | | |\/| | _|| .` | __ | | |\/| | (_) | .` | (_ | */
/* |___/|___| |_| |_||_/_/ \_\_| |___/ \___/___| |_| |_|___|_|\_|_||_| |_| |_|\___/|_|\_|\___| */
#include <bits/stdc++.h>
using namespace std;
int a[500009];
int n;
bool check(int mid) {
int x = lower_bound(a+1,a+1+n,mid)-a;
if (x>n) return mid==0;
return (n-x+1>=mid);
// int dem=0;
// for (int i = n; i > 0; --i) {
// if (a[i]>=mid) ++dem;
// else break;
// if (dem>=mid) return true;
// }
// return dem>=mid;
}
int main() {
// ios_base::sync_with_stdio(1+1==3);
// cout.tie(nullptr); cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a+1,a+1+n);
int l=0,r=a[n];
int res;
while (l<=r) {
int mid = (l+r)/2;
// cout << mid << endl;
if (check(mid)) {
res=mid;
l=mid+1;
} else {
r=mid-1;
}
}
cout << res;
}
/*
Hôm nay trời vẫn mưa tầm tã,trốn việc lang thang một tiếng trên đường..
Từng hạt mưa rơi xuống đầu,văng xuống đường, tan ra từng mảnh vụn,hòa vào dòng nước...rồi theo nhau chui vào lỗ cống..he he
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |