Codeforces Round #303 (Div. 2) D 贪心
1 second
256 megabytes
standard input
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.
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.
5
15 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.
题意:排队问题 对于某个人 当排在他前面的人的总时间大于他的预约时间时 就会失去预约
现在任意更改序列,问最多有多少人 不会失去预约;
题解:拍个序 贪心就可以了
这是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 贪心的更多相关文章
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 水题 Codeforces Round #303 (Div. 2) D. Queue
题目传送门 /* 比C还水... */ #include <cstdio> #include <algorithm> #include <cstring> #inc ...
- DP Codeforces Round #303 (Div. 2) C. Woodcutters
题目传送门 /* 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 问最多能砍到多少棵树 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 分情况讨论,若符合就取最 ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #303 (Div. 2)(CF545) E Paths and Trees(最短路+贪心)
题意 求一个生成树,使得任意点到源点的最短路等于原图中的最短路.再让这个生成树边权和最小. http://codeforces.com/contest/545/problem/E 思路 先Dijkst ...
- 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 ...
- Codeforces Round #303 (Div. 2) D. Queue —— 贪心
题目链接:http://codeforces.com/problemset/problem/545/D 题解: 问经过调整,最多能使多少个人满意. 首先是排序,然后策略是:如果这个人对等待时间满意,则 ...
随机推荐
- UVa 11426 - GCD - Extreme (II)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- elasticsearch插件之一:marvel
在 安装插件的过程中,尤其是安装Marvel插件遇到了很多问题,又要下载license.Marvel-agent,又要下载安装Kibana,很多内容 不知道为何这样安装处理.仔细看了看ElasticS ...
- oracle数据库常用SQL语句(11.29更新)
笔者日常工作中常用到的sql语句,现总结如下,留作日后查看. 1.按照两列中的最大值取 ,只取两列其中的一列 SELECT * FROM t_doc T ORDER BY GREATEST(T.Loa ...
- Opencv的基础结构与内容
- io函数
io函数一般分为两大类: 系统(不带缓存)调用: 如read.write.open 标准(带缓存)调用: fread.fwrite.fopen 上面说的带缓存/不带缓存是针对用户态的,内核态本身都是带 ...
- 支持单色条码图像生成的条形码控件Barcode Professional
Barcode Professional for .NET Windows Forms条形码控件是一款灵活和强大的.NET组件(.NET DLL 类库),它让您轻松地添加条码生成和打印功能到您的.NE ...
- 【转发】查看Linux版本系统信息方法汇总
Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然. 1.# uname -a (Linux查看版本当前操作系统内核信息) L ...
- jQuery dialog 简介
dialog是jQuery UI 库的一个UI组件,所以使用dialog时,不仅要引入jQuery.js(因为它只是轻量级的基础框架),还需要引入jQueryUI的js及相关css文件 示例: < ...
- iOS中Block使用探索
Block介绍 Block在ios 4.0之后加入,并大量使用在新的ios api中.block是一个匿名的代码块,可以传递给其他对象的参数,并得到返回值.从本质上讲,block同其他普通的变量类似, ...
- 同是url参数传进来的值,String类型就用getAttribute获取不到,只能用getParameter获取,而int就两个都可以这是为什么?
这是因为int的属性是id,这是在被放到modeldriver中的user所具有的属性,传递过来的参数如果和user的属性重名,struts2的有类似beanutil之类的工具会自动封装参数,这时候用 ...