Codeforces Round #510 (Div. 2) A.Benches(鸽巢原理)

题意:告诉你开始每个凳子坐的人数,问再来m个人,最大的某个凳子最多人数和最小的某个凳子最多人数是多少。

思路:最大的就是原来最多的人数加上m,最小的要用鸽巢原理,计算出平均每个凳子的最少人数,再和开始的最大人数比较取大的。这里用(s-1)/n+1是因为这里人数不能为小数,只能往大了取。

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn=200005;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int n,m,a[10005],s=0,maxx=0,minn=inf;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
        maxx=max(maxx,a[i]);
        minn=min(minn,a[i]);
    }
    s+=m;
    if(n==1)
        cout<<s<<" "<<s<<endl;
    else
    cout<<max((s-1)/n+1,maxx)<<" "<<maxx+m<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Dilly__dally/article/details/82762322