Codeforces 545D
来源:互联网 发布:美国经济数据日历 编辑:程序博客网 时间:2024/06/08 08:41
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.
The first line contains integer n (1 ≤ n ≤ 105).
The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.
Print a single number — the maximum number of not disappointed people in the queue.
515 2 1 5 3
4
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
#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int ,int > P;const int MAX_N = 1e5+9;priority_queue <int ,vector<int> , greater<int > > que;int main(){ int N,M,T; while(cin>>N) { while(!que.empty()) que.pop(); for(int i=0;i<N;i++) { int t; scanf("%d",&t); que.push(t); } int sum = 0; int ans = 0; while(!que.empty()) { int temp = que.top();que.pop(); if(sum <= temp ) { sum += temp; ans ++; } } cout<<ans<<endl; } return 0;}
- CodeForces 545D贪心
- Codeforces-545D. Queue
- codeforces 545D. Queue
- Codeforces-545D-Queue
- Codeforces 545D
- codeforces 545D Queue
- [贪心] Codeforces #545D. Queue
- Codeforces 545D Queue【贪心+模拟】
- CodeForces 617D CodeForces 617D
- CodeForces 101D
- CodeForces 103D
- CodeForces 222D Olympiad
- codeforces 242d
- CodeForces 111D
- 【codeforces】3D
- CodeForces 127D Password
- codeforces 257D. Sum
- Codeforces 292D
- shell中的重定向 1>&2 2>&1 >&2
- JAVA JDK动态代理和CGLIB动态代理
- 2017多校训练八-1011(hdu 6143 Killer Names)
- qt基础3
- JavaScript知识点之执行上下文
- Codeforces 545D
- Liunx环境启动tomact与查看日志
- spring源码解析-AOP原理
- 指定代码放哪个cpu运行
- Sequence
- 解决springMVC中Get请求乱码的问题
- AndroidStudio的CMake开发时遇到的异常及解决方案
- Eratosthenes筛法
- 基本Makefile编写举例