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 题解: 问经过调整,最多能使多少个人满意. 首先是排序,然后策略是:如果这个人对等待时间满意,则 ...
随机推荐
- bzoj 2326: [HNOI2011]数学作业
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...
- 开源性能测试工具--Jmeter介绍+安装
一. Apache JMeter介绍 1. Apache JMeter是什么Apache JMeter 是Apache组织的开放源代码项目,是一个100%纯Java桌 ...
- Python背景色与语法高亮主题配置
使用python idle的人恐怕都无法忍受默认的白色背景,及其语法高亮主题. 大家更倾向于使用黑色背景. 用户目录 的.idlerc 目录: 下面的各个系统下对应的该文件的位置: 在Linux系列系 ...
- 内工大acm校赛--整理代码
题目:小明搜到一行无缩进无换行代码,请帮小明整理代码.无for语句和case语句,而且只有一个主函数.你只要控制注意“:”“{”“}”这三个符号带来的缩进和换行效果就行. Input: 输入只有一行, ...
- ubuntu 防火墙 添加策略 解决mysql远程访问问题
ubuntu 的iptables 文件不在 init.d中 不能 service iptables restart 只修改 /etc/iptables 文件也不管用 sudo iptables -L ...
- SQL CAST, CONVERT 比较
本文转自:http://www.cnblogs.com/denylau/archive/2010/12/01/1893371.html if (@StartTime > @EndTime) ...
- HDU 1203-Program D
Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的 ...
- namenode 和datanode无法启动,错误:FSNamesystem initialization failed. datanode.DataNode: Incompatible namespaceIDs
问题一: namenode无法启动,查看日志,错误信息如下: org.apache.hadoop.hdfs.server.namenode.FSNamesystem: FSNamesystem ini ...
- HTML--8Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunme ...
- oracle中的cluster表
大家对通常oracle中的cluster的理解是不准确的,经常和sql server中的cluster index混淆.Cluster是存储一组table的一种方法,这些table共享同一数据块中的某 ...