fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector <int> a;
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int x;
  8. for(int i=0 ; i<n ; i++) {
  9. cin >> x;
  10. a.push_back(x);
  11. }
  12. int p;
  13. sort(a.begin(),a.end());
  14. for(int i=0 ; i<n ; i++) {
  15. if(i+1>a[i]){
  16. p=i;
  17. break;
  18. }
  19. }
  20. cout << p;
  21. return 0;
  22. }
Success #stdin #stdout 0s 4384KB
stdin
5
1 3 3 3 6
stdout
3