codeforces 545D Queue
来源:互联网 发布:网络机柜回收 编辑:程序博客网 时间:2024/06/05 21:52
点击打开链接
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.
题意:判断最多能有多少人接受服务。
分析:第i个人需要t[i]的服务,那就和它之前的所有时间和比较,如果小于等于当前的服务时间,就可以等,当然了,需要比较,以时间排序。
#include <bits/stdc++.h>using namespace std;const int N = 1e5;int main(){ int n; int t[N + 5]; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &t[i]); } sort(t + 1, t + n + 1); int a[N + 5]={0}; a[1] = t[1]; int k = 1; for(int i = 2; i <= n; i++) { if(a[k] <= t[i]) { a[k + 1] = a[k] + t[i]; k++; } } cout << k << endl; return 0;}
- Codeforces-545D. Queue
- codeforces 545D. Queue
- Codeforces-545D-Queue
- codeforces 545D Queue
- [贪心] Codeforces #545D. Queue
- Codeforces 545D Queue【贪心+模拟】
- codeforces 353D.Queue
- CodeForces 303D Queue
- Codeforces#303-D. Queue-水题
- Codeforces 353D Queue(规律)
- Codeforces 353D Queue【思维】好题~
- coderforce 545D Queue
- G-Queue(CF-545D
- Codeforces Round #303 (Div. 2)-D. Queue(优先队列)
- Codeforces Round #303 (Div. 2) D. Queue —— 贪心
- Codeforces Round #205 (Div. 2) D. Queue —— 技巧
- Codeforces Round #303 (Div. 2) D. Queue 【贪心】
- D. Queue
- 如何在3年内从一个2流程序员拿到30K+
- 二维码生成_
- codeforces 878 A short programme
- Google Pixel 2 发布会总结:主角是硬件,但核心依然是 AI
- Deepmind成立新AI部门,意在处理AI社会和伦理问题
- codeforces 545D Queue
- 345英亩的“亚马逊”城——这是乔治亚州为吸引电商巨头开出的价码
- 谷歌发布新品:AI First?硬件为王?现象之下,你该看到本质
- Efinix可编程芯片:可进一步推动人工智能技术发展
- TCP_Socket及源代码01
- cxf webservice 完整例子
- 迅雷创始人程浩:人工智能创业的6大核心问题
- mac下安装mysql5.7.18,连接出现Access denied for user 'root'@'localhost' (using password: YES)
- 树上的 DP