0%

Codeforces 1042A

Codeforces 1042A - Benches

Benches

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

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

Nobody leaves the taken seat during the whole process.

Input:

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

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

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

Output:

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

範例:

input:

1
2
3
4
5
6
4
6
1
1
1
1

output:

1
3 7

input:

1
2
3
1
10
5

output:

1
15 15

input:

1
2
3
4
5
3
6
1
6
5

output:

1
6 12

input:

1
2
3
4
5
3
7
1
6
5

output:

1
7 13

Note:

In the first example, each of four benches is occupied by a single person. The minimum k is 3. 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 k is 7. That requires all six new people to occupy the same bench.

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

題意:

有n張椅子,上面各有ai個人,現在又來了m個人,問你所有人都坐上椅子後,最多人的椅子最少跟最多會有多少人?

思路:

先記錄原本最多人的椅子(假設有x人),在加入m個人後,最多人的椅子最少不可能比原本最多的少(x),最多就是m個人都做到原本最多人的椅子上(x+m)。因此用二分搜尋法搜尋x~x+m,紀錄最小值。

程式碼: