题干:

There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of nn available.

Let kk be the maximum number of people sitting on one bench after additional mmpeople came to the park. Calculate the minimum possible kk and the maximum possible kk.

Nobody leaves the taken seat during the whole process.

Input

The first line contains a single integer nn (1≤n≤100)(1≤n≤100) — the number of benches in the park.

The second line contains a single integer mm (1≤m≤10000)(1≤m≤10000) — the number of people additionally coming to the park.

Each of the next nn lines contains a single integer aiai (1≤ai≤100)(1≤ai≤100) — the initial number of people on the ii-th bench.

Output

Print the minimum possible kk and the maximum possible kk, where kk is the maximum number of people sitting on one bench after additional mm people came to the park.

Examples

Input

4
6
1
1
1
1

Output

3 7

Input

1
10
5

Output

15 15

Input

3
6
1
6
5

Output

6 12

Input

3
7
1
6
5

Output

7 13

Note

In the first example, each of four benches is occupied by a single person. The minimum kk is 33. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum kk is 77. That requires all six new people to occupy the same bench.

The second example has its minimum kk equal to 1515 and maximum kk equal to 1515, as there is just a single bench in the park and all 1010 people will occupy it.

解题报告:

maxx很好弄,全加在那个最大的上就可以了。(也就是最大可能的最大值)

主要是minn:(最小可能的最大值)

这题做法很多,可以直接优先队列模拟,这种题见过很多个了。

还有一个方法,因为要输出最小的最大值,所以直接看看能不能把其余的都变成最大的,然后剩下的再均摊。如果不够都变成最大的,那最大的那个就是答案。

刚开始有一个错误的想法,就是上来就平均分,然后剩余的多的再加到最小的身上。这样错误想法的产生,就是因为没有注意到答案的特点:肯定要大于等于那个最大的。

AC代码:

#include<bits/stdc++.h>using namespace std;
int n,m;
int a[1000 + 5];
priority_queue<int,vector<int>,greater<int> > pq;
int main()
{cin>>n>>m;for(int i = 1; i<=n; i++) scanf("%d",a+i),pq.push(a[i]);sort(a+1,a+n+1);int maxx = a[n] + m;int minn = 0;for(int i = 1 ; i<=m; i++) {int cur = pq.top();pq.pop();pq.push(cur+1);}for(int i = 1; i<=n; i++) {minn = max(minn,pq.top());pq.pop();}printf("%d %d\n",minn,maxx);return 0;
}

当时的错误想法:

//   for(int i = 1; i<=n; i++) a[i]+=(m/n);
//  m%=n;
//  for(int i = 1; i<=m; i++) a[i]++;
//  minn = *max_element(a+1,a+n+1);

总结:先分析清楚问题,再动手敲代码。

【CodeForces - 1042A】Benches (优先队列,思维模拟,maxmin问题)相关推荐

  1. Magic Powder - 1 CodeForces - 670D1(优先队列进一步理解)

    写这个题的时候一直在想怎么才能动态排序(一遍改变数值,一遍从新改变相应的顺序),到最后才突然想起来这不就是优先队列吗,通过这题对优先队列的动态排序有了进一步理解.好题! AC代码: #include ...

  2. SDU程序设计思维实践题目总结

    题目来源及链接 题目名称及讲解博客链接 涉及算法 原题以及原题链接 第二周作业 Maze BFS POJ-3984 Pour water BFS POJ-1606 第二周实验 化学 模拟 codefo ...

  3. Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列

    链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行 ...

  4. 贪心(优先队列) - New Year Snowmen - CodeForces - 140C

    贪心(优先队列) - New Year Snowmen - CodeForces - 140C 题意: 给定一个长度为n的正整数序列a1,a2,...,an.给定一个长度为n的正整数序列a_1,a_2 ...

  5. 【CodeForces - 1038C】Gambling (博弈问题,优先队列模拟,贪心)

    题干: Two players A and B have a list of nn integers each. They both want to maximize the subtraction ...

  6. *【CodeForces - 574A】Bear and Elections (优先队列,水题模拟)

    题干: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections a ...

  7. CodeForces 140C New Year Snowmen (贪心+优先队列)

    题意:n个数,选三个严格下降的数为一组,求最多能选多少组,并列出每组哪些数. 题解:贪心+优先队列 最多能选多少组,那么必须贪心数量多的. 例如:1 1 2 3 4 5 如果按照数的大小排序,只能贪到 ...

  8. Potions CodeForces - 1526C1/1526C2(优先队列)

    Potions(Easy Version) Potions(Hard Version) 题意: 从左往右喝药,在保证自己的生命值hp>0的情况下,尽可能喝更多的药 思路: 碰到加hp的,就可以喝 ...

  9. Codeforces Raif Round 1 (Div. 1 + Div. 2) E. Carrots for Rabbits(优先队列+贪心)

    原题链接 题意 有N个萝卜,K只兔子,要求把N个萝卜分成K份,一个兔子吃一个长为X的萝卜的时间为X*X,求怎么分能使最后的时间最短. 思路 刚看到这个题的时候,刚开始的思路是,把所有的萝卜都存在一个大 ...

最新文章

  1. Injection of @Reference dependencies failed;
  2. IT项目监理的三种模式比较
  3. 软件开发生命周期中的设计阶段_BIM咨询在设计阶段包含哪些内容?体现了哪些价值?...
  4. Collections.toMap 报错 空指针 key重复
  5. 微信小程序|开发实战篇之七-steps进度条组件
  6. gsoap 实现 C/C++ 调用web service
  7. vue-cli3.x中使用axios发送请求,配合webpack中的devServer编写本地mock数据接口(get/post/put/delete)...
  8. VC:CString用法整理
  9. SW转发与MAC地址表
  10. 正则表达式 - 中文、英文姓名匹配
  11. 曙光服务器面板显示感叹号,磁盘阵列和磁带库面板感叹号灯橙色
  12. oracle中的INTERVAL函数用法
  13. 【Joy of Cryptography 读书笔记】Chapter 5 伪随机数生成器(Pseudorandom Generator)
  14. <video> 标签快进不生效
  15. druid数据源下 sqlserver 出现 对象名 'xxx' 无效
  16. Ubuntu 10.10下编译安装无线网卡
  17. android开发笔记之高级主题—传感器的简单介绍
  18. 金融行业的VC风险投资,PE私募股权,LP有限合伙人,GP普通合伙人
  19. 常用算法的算法思想以及基本特征
  20. 一款牛逼的Java工具类库,GitHub星标10.7k+,你敢用吗?

热门文章

  1. 华为做raid5步骤_华为验厂验厂流程如何?主要内容是什么呢?
  2. 安卓开发toolbar设置logo_Android之ToolBar的使用
  3. 背景图层和普通图层的区别_008Photoshop四赞图层(图层样式)
  4. future.cancel不能关闭线程_彻底弄懂线程池-newFixedThreadPool实现线程池
  5. 将chart放入panel中出现滚动条_聊天场景在web前端开发中的体验与优化
  6. mediawiki mysql_MediaWiki
  7. 无线 在linux叫什么地方,请问有知道atheros无线网卡Linux驱动官方下载地址是什么吗?...
  8. 英语答题测试的软件叫什么,英语做题软件哪个好 有答案解析的英语做题软件分享...
  9. VC嵌入python时debug版lib下载
  10. Linux Arch目录下处理器体系架构介绍