Codeforces Round #134 (Div. 2) B. Airport
来源:互联网 发布:立式包装机编程 编辑:程序博客网 时间:2024/06/02 08:57
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 npassengers 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.
代码如下:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;bool cmp(int a,int b){ return a>b;}int main(){ int n,m,i,j,k,min,max; int a[1005],b[1005],s,t; while(~scanf("%d%d",&n,&m)) { min=0; max=0; s=n; t=n; for(i=0;i<m;i++) { cin>>a[i]; b[i]=a[i]; } sort(a,a+m); sort(b,b+m,cmp); for(i=0;i<m;i++) { while(a[i]>0&&s>0) { min+=a[i]; a[i]--; s--; } } while(t>0) { for(i=0;i<m&&t>0;i++) { if(b[i]>0&&b[i]>b[i-1]) { max+=b[i]; b[i]--; t--; } } } printf("%d %d\n",max,min); } return 0;}
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #134 (Div. 2) B. Airport
- Codeforces Round #134 (Div. 2)——B
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- Codeforces Round #206 (Div. 2) - b
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #203 (Div. 2)B
- Codeforces Round #203(Div. 2)B. Resort
- Codeforces Round #206 (Div. 2)B
- 那是光的短暂或恒久吗?
- java.security.MessageDigest的使用,MD5,安全密令
- 翻硬币 贪心
- 别再仰望别人,自己就是风景
- 统的基本组成;中文Windows操作系统;字处理
- Codeforces Round #134 (Div. 2) B. Airport
- 字节流测试小程序InputStream
- JAVA SWING 系统托盘(右下角小图标)
- 数据分析,展现与R语言学习笔记(2)
- C++静态成员函数小结
- 【设计模式】设计模式之单例模式
- 中国海军首艘052D型驱逐舰昆明舰正式服役
- 今年1月23日我曾发表文章《对联想“吃剩饭”策略的简单解读》探讨联想以23亿美元
- cuda编程------矩阵乘法