题目:
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.
输入:
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.
输出:
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.
样例输入:
4 6 1 1 1 1
样例输出:
3 7
样例输入:
1 10 5
样例输出:
15 15
样例输入:
3 6 1 6 5
样例输出:
6 12
样例输入:
3 7 1 6 5
样例输出:
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.
大体题意就是公园里有k把长椅,第i把长椅上会坐着ai个人,然后又会再来m个人,这m个人每个人都会找一把长椅坐下,问这m个人坐下了之后人数最多的长椅上最多会有多少人,最少会有多少人。
最多会有多少人很容易想到,在m个人没来之前人数最多的长椅上加上m,就是最多。
要保证最多上的最少,可以先用sort排一下序,目前人数最多的长椅先不坐人,现在其他人数少的长椅上坐人,坐完之后,如果还有剩余,那就看剩下的人能不能整除n,如果能,最小的数就是a[n]+(m/n),如果不能,肯定有几个椅子会再做一个人,那么最小的数就是a[n]+(m/n)+1;
AC代码:
import java.math.BigInteger;
import java.net.StandardSocketOptions;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.math.*;
import java.util.Scanner;
public class Main {
public static Map<Integer,Integer>mapp=new HashMap<Integer,Integer>();
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
int m=cin.nextInt();
int []a=new int[105];
for(int i=1;i<=n;i++)
{
a[i]=cin.nextInt();
}
Arrays.sort(a,1,n+1);
int mm=m;
for(int i=1;i<=n;i++)
mm-=a[n]-a[i];
if(mm<=0)
{
System.out.println(a[n]+" "+(a[n]+m));
}
else
{
if(mm%n==0)
System.out.println(a[n]+(mm/n)+" "+(a[n]+m));
else if(mm%n!=0)
System.out.println(a[n]+(mm/n)+1+" "+(a[n]+m));
}
}
}
1329

被折叠的 条评论
为什么被折叠?



