CF218B.Airport

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 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.

洛莱克和博莱克即将乘飞机出国旅行。当地机场推出了一项特殊的“自主选机”优惠活动,其规则如下:

  • 乘客可自行选择乘坐哪一架飞机;
  • 若某架飞机当前有 xx 个空座位(其中 x>0x > 0),则乘坐该飞机的机票价格为 xx 兹罗提(波兰货币单位)。

机场唯一的售票处前已排起了由 nn 名乘客组成的队伍。洛莱克和博莱克尚未加入队列,但他们已经开始思考:在所有 nn 名乘客均按该优惠活动规则购票的前提下,机场管理部门最多和最少能收入多少兹罗提?

乘客按顺序购票:队首的第一位乘客最先购票,随后是第二位,依此类推,直至第 nn 位乘客。

输入格式

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.

第一行包含两个整数 nn 和 mm(1≤n,m≤10001 \leq n, m \leq 1000),分别表示队列中的乘客数量和机场中的飞机数量。
下一行包含 mm 个整数 a1,a2,…,ama_1, a_2, \dots, a_m(1≤ai≤10001 \leq a_i \leq 1000),其中 aia_i 表示第 ii 架飞机在售票处开始售票前的空座位数。

每行中的数字以空格分隔。题目保证所有飞机的空座位总数至少为 nn。

输出格式

Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.

输出两个整数——机场管理部门所能获得的最大和最小兹罗提(zlotys)金额,分别对应。

输入输出样例

  • 输入#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.

在第一个测试样例中,乘客数量等于空座位数量,因此无论选择飞机的顺序如何,管理部门获得的收益总和都相同。

在第二个样例中,当队列中的第 1 位乘客购买第 1 架飞机的机票、第 2 位乘客购买第 2 架飞机的机票、第 3 位乘客购买第 3 架飞机的机票、第 4 位乘客购买第 1 架飞机的机票时,收益总和最大;当队列中的第 1 位乘客购买第 1 架飞机的机票、第 2 位乘客购买第 1 架飞机的机票、第 3 位乘客购买第 2 架飞机的机票、第 4 位乘客购买第 2 架飞机的机票时,收益总和最小。

输入解题思路,AI测评打分。不知道怎么写?

首页