原题链接:http://codeforces.com/contest/1042/problem/A
Benches
There are benches in the Berland Central park. It is known that people are currently sitting on the -th bench. Another people are coming to the park and each of them is going to have a seat on some bench out of available.
Let be the maximum number of people sitting on one bench after additional people came to the park. Calculate the minimum possible and the maximum possible .
Nobody leaves the taken seat during the whole process.
Input
The first line contains a single integer — the number of benches in the park.
The second line contains a single integer — the number of people additionally coming to the park.
Each of the next lines contains a single integer — the initial number of people on the -th bench.
Output
Print the minimum possible and the maximum possible , where is the maximum number of people sitting on one bench after additional 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 is . 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 is . That requires all six new people to occupy the same bench.
The second example has its minimum equal to and maximum equal to , as there is just a single bench in the park and all people will occupy it.
题解
我都不知道我为什么要排序 (可能是身处排序强校的缘故吧)。
代码
#include<bits/stdc++.h>
using namespace std;
int a[105],maxn,n,m;
void in(){scanf("%d%d",&n,&m);for(int i=1;i<=n;++i)scanf("%d",&a[i]);}
void ac()
{
sort(a+1,a+1+n);maxn=a[n]+m;
for(int i=1;i<=n;++i)m-=a[n]-a[i];
if(m<0)printf("%d",a[n]);
else printf("%d",a[n]+m/n+(bool)(m%n));
printf(" %d",maxn);
}
int main(){in();ac();}