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 ;
}

Codeforces Round #303 (Div. 2) D 贪心的更多相关文章

  1. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  2. 水题 Codeforces Round #303 (Div. 2) D. Queue

    题目传送门 /* 比C还水... */ #include <cstdio> #include <algorithm> #include <cstring> #inc ...

  3. DP Codeforces Round #303 (Div. 2) C. Woodcutters

    题目传送门 /* 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 问最多能砍到多少棵树 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 分情况讨论,若符合就取最 ...

  4. 水题 Codeforces Round #303 (Div. 2) A. Toy Cars

    题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...

  5. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  6. Codeforces Round #303 (Div. 2) C. Woodcutters 贪心

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...

  7. Codeforces Round #303 (Div. 2)(CF545) E Paths and Trees(最短路+贪心)

    题意 求一个生成树,使得任意点到源点的最短路等于原图中的最短路.再让这个生成树边权和最小. http://codeforces.com/contest/545/problem/E 思路 先Dijkst ...

  8. Codeforces Round #303 (Div. 2) E. Paths and Trees 最短路+贪心

    题目链接: 题目 E. Paths and Trees time limit per test 3 seconds memory limit per test 256 megabytes inputs ...

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

    题目链接:http://codeforces.com/problemset/problem/545/D 题解: 问经过调整,最多能使多少个人满意. 首先是排序,然后策略是:如果这个人对等待时间满意,则 ...

随机推荐

  1. js 获取div 图片高度

    使用jquery获取网页中图片的高度其实很简单,有两种常用的方法都可以打到我们的目的 $("img").whith();(返回纯数字) $("img").css ...

  2. string.format

    string.Format("{0:#,0}", c.num), //千分号,有小数就保留2位小数 string.Format("{0:N2}", c.amou ...

  3. Stern-Brocot树 及 法里级数分析

    Stern-Brocot树产生了所有分子分母互素的分数 从初始0/1 1/0 -> m/n m'/n'出发,不断往中间添加 (m+m')/(n+n')容易推得 n * m' - m * n' = ...

  4. LightOJ 1047-Program C

    Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue ...

  5. SQL学习心得(转)

    http://www.cnblogs.com/lyhabc/p/3732942.html

  6. Android的R.java文件

    1.Android资源管理简介: Android应用程序资源可以分为两大类,分别放在assets和res文件夹下.assets目录下保存的是一些原始的文件,可以以任何方式来进行组织.这些文件最终会被原 ...

  7. hdu 1069

    //Accepted 264 KB 0 ms //每种block只有三种方法,且每种放法至多放一次 //规定三条边的顺序后 //把所有的block按x递增排序,x相同则按y递增排序 //然后dp // ...

  8. CPU MPU MCU SOC SOPC关系及区别

    在嵌入式开过程,会经常接触到一些缩写术语概念,这些概念在嵌入式行业中使用率非常高,下面我们就解释一下这些概念之间的关系和区别: 1.CPU(Central Processing Unit),是一台计算 ...

  9. hdu 2071

    Ps:输出n个数里最大的 #include "stdio.h" int main(){ ],max; int i,j,n,t; while(~scanf("%d" ...

  10. IOS第三方库 MARK

    综合github上各个项目的关注度与具体使用情况,涵盖功能,UI,数据库,自动化测试,编程工具等类型,看完,还敢自称”精通iOS开发”吗? https://github.com/syedhali/EZ ...