Polycarp Training

Posted karshey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Polycarp Training相关的知识,希望对你有一定的参考价值。

Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day — exactly 2 problems, during the third day — exactly 3 problems, and so on. During the k-th day he should solve k problems.

Polycarp has a list of n contests, the i-th contest consists of ai problems. During each day Polycarp has to choose exactly one of the contests he didn’t solve yet and solve it. He solves exactly k problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least k problems that Polycarp didn’t solve yet during the k-th day, then Polycarp stops his training.

How many days Polycarp can train if he chooses the contests optimally?

Input
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of contests.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤2⋅105) — the number of problems in the i-th contest.

Output
Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.

Examples

Input
4
3 1 4 1
Output
3
Input
3
1 1 1
Output
1
Input
5
1 1 1 2 2
Output
2

2*10^5竟然是200000…
数组开小了会TL。

#include<iostream>
#include<algorithm>
using namespace std;
const int N=200005;
int main()
{
	long long int n,a[N];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int d=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>=d+1) d++;
	}
	cout<<d;
	return 0;
}

以上是关于Polycarp Training的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 1005D Polycarp and Div 3(思维贪心dp)

Codeforces 861D - Polycarp's phone book

C. Polycarp Restores Permutation

Codeforces Round #734 (Div. 3)-A. Polycarp and Coins-题解

Codeforces Round #734 (Div. 3)-A. Polycarp and Coins-题解

codeforces723----C. Polycarp at the Radio