Codeforces Round #134 (Div. 2) B. Airport

37 篇文章 0 订阅


B. Airport
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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

Sample test(s)
input
4 3
2 1 1
output
5 5
input
4 3
2 2 2
output
7 6
Note

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.

题意:输入n和m,分别代表乘客的数量和飞机的数量,下一行包括m个数,分别代表还剩余的票数,规定剩余票数x张,则成本为x,求当n个乘客都买票之后,成本最高和最低分别是多少?求最高,按从大到小排序,求最低,则从小到大排序。

代码如下:

#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;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值