301168: CF218B. Airport
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Airport
题意翻译
n个乘客,m架飞机,每个乘客按顺序挑选一架飞机并买票,票价为他挑选的飞机的空位数,求航空公司可以赚取的最大价钱和最小价钱。题目描述
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 $ a_{1},a_{2},...,a_{m} $ $ (1<=a_{i}<=1000) $ — $ a_{i} $ 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.
输入输出样例
输入样例 #1
4 3
2 1 1
输出样例 #1
5 5
输入样例 #2
4 3
2 2 2
输出样例 #2
7 6