fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long long t, n, temp, x, s;
  5. long long arr[1001];
  6.  
  7. int main() {
  8. cin >> t;
  9. for (int i = 0; i < t; i++) {
  10. cin >> n;
  11. for (int j = 1; j <= n; j++) {
  12. cin >> arr[j];
  13. }
  14. for (int j = 1; j <= n; j++) {
  15. temp = arr[j];
  16. x = j-1;
  17. while (x>0 && arr[x] <= temp) {
  18. arr[x+1] = arr[x];
  19. x--;
  20. }
  21. arr[x+1] = temp;
  22. }
  23. s = 1;
  24. while (arr[s] >= s) {
  25. s++;
  26. }
  27. cout << s-1 << endl;
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5384KB
stdin
4
5
4 3 1 4 5
4
4 4 4 4
3
1 1 1
5
5 5 1 1 5
stdout
3
4
1
3