题目链接:
https://pintia.cn/problem-sets/994805260223102976/problems/994805269312159744
AC代码:
//分析:从下标1开始存储n天的公里数在数组a中,对n个数据从大到小排序,i表示了骑车的天数,
//那么满足a[i] > i的最大值即为所求
//数学问题,
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000000];
bool cmp1(int a, int b) {
return a > b;
}
int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a+1, a+n+1, cmp1);
int ans = 0, p = 1;
while(ans <= n && a[p] > p) {
ans++;
p++;
}
printf("%d", ans);
return 0;
}