Codeforces Round #510 #A

http://codeforces.com/contest/1042/problem/A

题目大意就是:

现在公园里有n个长椅(要多长有多长),第i个长椅上有a[i]个人(泰山崩于前而不乱),现在又有m个人来到公园,都要坐在长椅上上,问这些人都坐下后,这么多长椅中最少一个座位上有多少个人,最多有多少个人。

很显然最多有多少个人当然是这m个人全做到人最多的那个长椅上咯。

要求最少的话,那么我们求一个总人数做到长椅上的平均值(向上取整),把这些人均分到每个座椅上每个最少有多少个人,然后我们还需要判断一开始就坐在长椅上的人数最大值是否大于这个数,输出最大值。

比赛时好气哦,倒数第5行的输出少了个空格,被某不知名大佬(hun dan)hack。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int n,a[106],m,MAX,sum;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
        MAX=max(MAX,a[i]);
    }
    sum+=m;
    int ren=sum/n,yu=sum%n;
    if(yu!=0)
    {
        if(MAX>ren+1)printf("%d ",MAX);
        else printf("%d ",ren+1);
    }
    else
    {
        if(MAX>ren)printf("%d ",MAX);
        else printf("%d ",ren);
    }
    printf("%d",MAX+m);
}

猜你喜欢

转载自www.cnblogs.com/rmy020718/p/9667550.html
今日推荐