B. Airport
来源:互联网 发布:淘宝店新手该怎么做 编辑:程序博客网 时间:2024/05/16 23:37
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on;
- if the chosen plane has x (x > 0) empty seats at the given moment, then the ticket for such a plane costs x zlotys (units of Polish currency).
The only ticket office of the airport already has a queue of n passengers in front of it. Lolek and Bolek have not stood in the queue yet, but they are already wondering what is the maximum and the minimum number of zlotys the airport administration can earn if all n passengers buy tickets according to the conditions of this offer?
The passengers buy tickets in turn, the first person in the queue goes first, then goes the second one, and so on up to n-th person.
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains m integers a1, a2, ..., am (1 ≤ ai ≤ 1000) — ai stands for the number of empty seats in the i-th plane before the ticket office starts selling tickets.
The numbers in the lines are separated by a space. It is guaranteed that there are at least n empty seats in total.
Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
4 32 1 1
5 5
4 32 2 2
7 6
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd plane, the 3-rd person — to the 3-rd plane, the 4-th person — to the 1-st plane. The sum is minimized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 1-st plane, the 3-rd person — to the 2-nd plane, the 4-th person — to the 2-nd plane.
解题说明:此题其实对一组数字进行处理,首先是进行排序,顺序为从小到大。为了求最小值,其实就是取满足条件的前k个数字,要求最大值也就是求满足条件的后p的数字。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int n,m,i;int c,t;int min,max;int a[1001];scanf("%d %d",&n,&m);for(i=0;i<m;i++){scanf("%d",&a[i]);}sort(a,a+m);t=n;min=0;max=0;for(i=0;i<m;i++){c=a[i];while(c&&t>0){min+=c;c--;t--;}if(t<=0){break;}}while(n){max+=a[m-1];a[m-1]--;n--;sort(a,a+m);}printf("%d %d\n",max,min);return 0;}
- B. Airport
- Codeforces 218B Airport
- Codeforces 218B Airport
- [Codeforces] 218B - Airport
- Airport
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #134 (Div. 2) B. Airport
- Codeforces---Airport
- LA4725 Airport
- uva1450 - Airport
- Airport Express
- UVA1450-Airport
- uva1450 - Airport
- uva1450-Airport
- uva11168 Airport
- Airport Express
- HDU5046-Airport
- Transferring @ Changi airport singapore
- VB.NET Datagridview 增加列用来显示进度条
- Android全屏显示的代码,用于拍照(代码非原创)
- 11g oracle 用户密码过期问题
- java连接Mysql数据库
- 清理缓存的shell脚步
- B. Airport
- 惠普M1213打印机如何关闭打印状态消息
- 尝试运行项目时出错:方法不存在
- 求子数组的最大和
- 13个JavaScript网站制作中实用技巧
- asp.net分页控件实例源码
- [收藏]javascript keycode大全
- Red and Black(广搜,迷宫)
- 实现动态创建html元素功能