英文题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805354762715136
中文题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805269312159744
1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 using namespace std; 5 6 int main() { 7 int n; 8 cin>>n; 9 vector<int> v(n),ans(n+1); 10 for(int i = 0; i < n; ++i) cin>>v[i]; 11 sort(v.begin(),v.end()); 12 int j = 0; 13 for(int i = 0; i <= n; ++i) { 14 while(j < n && i >= v[j]) ++j; 15 ans[i] = n-j; 16 } 17 for(int i = n; i >= 0; --i) { 18 if(ans[i] >= i) { 19 printf("%d",i); 20 break; 21 } 22 } 23 return 0; 24 }
原文:https://www.cnblogs.com/keep23456/p/12526411.html