Codeforces Round #303 (Div. 2) D 贪心

时间:2022-09-22 08:35:22
D. Queue
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

题意:排队问题  对于某个人 当排在他前面的人的总时间大于他的预约时间时 就会失去预约

现在任意更改序列,问最多有多少人 不会失去预约;

题解:拍个序 贪心就可以了

这是D题?

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int n;
ll a[];
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%I64d",&a[i]);
sort(a+,a++n);
ll exm=;
int ans=;
for(int i=; i<=n; i++)
{
int j;
if(a[i]>=exm)
{
ans++;
exm+=a[i];
for( j=i+; j<=n; j++)
{
if(a[j]>=exm)
break;
}
}
i=j-;
}
cout<<ans<<endl;
return ;
}