D - 你以为这是一道英文题其实是一道送分题

Little girl Susie went shopping with her mom and she wondered how to improve service quality.

There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.

Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.

Input

The first line contains integer n (1 ≤n≤ 105).

The next line contains n integers ti (1 ≤ti≤ 109), separated by spaces.

Output

Print a single number — the maximum number of not disappointed people in the queue.

Examples

Input

5

15 2 1 5 3

Output

4

Note

Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.

机翻:这个女孩苏西和她妈妈一起去购物,她想知道如何提高服务质量。

队列中有N个人。对于每个人,我们都知道我需要什么时候为他服务。如果一个人等待的时间超过了为他服务所需的时间,他会失望的。一个人等待的时间是所有站在他前面排队的人都被服务的总时间。苏西认为,如果我们交换一些排队的人,那么我们就可以减少失望的人数。

帮助Susie了解通过交换队列中的人可以达到的最大不失望人数。

输入

第一行包含整数n(1≤n≤105)。

下一行包含n个整数ti(1≤≤109),用空格分隔。

输出

打印一个数字-队列中不失望的最大人数。


贪心+排序,参考网址:

贪心算法_360百科

Codeforces-545D-Queue - 猩猩是个好程序员的博客 - CSDN博客

C语言入门:插入排序(代码实现,而不是排序方法阐述) - Rivival_S 的博客 - CSDN博客


#include<cstdio>

#include<cstring>

#include<algorithm>

#include<iostream>

using namespace std;

int a[100005];

int main() {

int n;

while(scanf("%d",&n)!=EOF) {

for(int i=0;i<n;i++)

scanf("%d",&a[i]);

sort(a,a+n);

int sum=1;

int t=a[0];

for(int i=1;i<n;i++) {

if(a[i]>=t) {

sum++;

t+=a[i];

}

}

printf("%d\n",sum);

}

return 0;

} --------------------- 作者:ypopstar 来源:CSDN 原文:https://blog.csdn.net/Ypopstar/article/details/52507284 版权声明:本文为博主原创文章,转载请附上博文链接!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容