CF218B.Airport

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 xx (x>0) empty seats at the given moment, then the ticket for such a plane costs xx zlotys (units of Polish currency).

The only ticket office of the airport already has a queue of nn 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 nn 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 nn -th person.

输入格式

The first line contains two integers nn and mm (1<=n,m<=1000)(1<=n,m<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains mm integers a1,a2,...,ama_{1},a_{2},...,a_{m} (1<=ai<=1000)(1<=a_{i}<=1000)aia_{i} stands for the number of empty seats in the ii -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 nn 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
    

说明/提示

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.

首页