GYM

来源:互联网 发布:sql server 下载的官网 编辑:程序博客网 时间:2024/06/05 11:31

Feeling of Comradeship
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

I was tired. Tired of hiding and wandering. Throw the rules out the window, odds are you'll go that way too. I just wanted everything to be finished. The crying heavens had already given a verdict for me, I was just looking for somebody to execute it. The castle of Dragon was not defenseless, it was ready for my visit. The beast inside me was woking up and rubbing his eyes.

I had already known every single bandit guarding Dragon's castle. It was quite useful to have connections in knight orders. There were only n men there. There had been some bigger frays. And not all of them desperately wanted to die by my hand that night. I knew that the i-th of them would have decided to fight only if at least ai other bandits had decided the same. I was slowly approaching the gates, wondering what was the maximal number of people who might have opposed me.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of bandits in the castle of Dragon.

The second line contains n integers separated by spaces: ai (0 ≤ ai ≤ 109) — the minimal number of other bandits with whom together the i-th bandit is ready to fight.

Output

Output a single integer — the maximal number of bandits that might be ready to fight for Dragon's castle.

Examples
input
64 2 1 6 0 3
output
5
input
61 3 6 1 3 5
output
4




题意:我也不知道题意是什么,完全是猜的…………试了好久,最后猜对了


解题思路:从后往前,找到第一个a[i]<i的就是了。


#include <iostream>#include <algorithm>using namespace std;int a[100005];int main(){    int n;    bool flag = false;    scanf("%d", &n);    for (int i = 1; i <= n; i++)    {        scanf("%d", &a[i]);    }    sort(a + 1, a + n + 1);    for (int i = n; i > 0; i--)    {        if (a[i] < i)        {            printf("%d\n", i);            flag = true;            break;        }    }    if (flag == false)        printf("0\n");}



原创粉丝点击