British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, he has even defined an "Eddington number", E -- that is, the maximum integer E such that it is for E days that one rides more than E miles. Eddington's own E was 87.
Now given everyday's distances that one rides for N days, you are supposed to find the corresponding E (≤N).
译:英国科学家爱丁顿喜欢骑行。据说为了展示他的技巧,他定义了一个"爱丁顿数",E —— 满足 E 天 骑行多余 E 公里 的最大的整数。爱丁顿自己的 E 是 87。现在给定 N 个每天的骑行距离,你应该找出相应的 E (≤N) 。
Each input file contains one test case. For each case, the first line gives a positive integer N (≤105), the days of continuous riding. Then N non-negative integers are given in the next line, being the riding distances of everyday.
译:每个输入文件包含一个测试用例。 对于每个用例,第一行给定一个正整数 N (≤105),表示贡献骑行的天数。接下来一行给定 N 个非负整数,表示每天的骑行距离。
For each case, print in a line the Eddington number for these N days.
译:对于每个测试用例,在一行中输出这 N 天的爱丁顿数。
10 6 7 6 9 3 10 8 2 7 8
6
#include<bits/stdc++.h> using namespace std ; vector<int> num ; int n ; bool cmp(int a, int b){ return a > b ; } int main(){ scanf("%d" , &n) ; num.resize(n + 1) ; for(int i = 1 ; i <= n ; i ++) scanf("%d" , &num[i]) ; sort(num.begin() + 1 , num.end() + 1, cmp) ; // 从大到小排序 for(int i = 1 ; i <= num.size() ; i ++){ if(num[i] <= i){ cout << i - 1 << endl ; break; } } return 0 ; }