Week9 作业 C - CodeForces - 1042A - 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.
思路:
很简单,求最大值就把所有人放到现在人最多的椅子;求最小值就把人均分到各个椅子
代码:
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> v;
int main()
{
//最大值的最大值就是最多的人加上y
//最大值的最小值要看是否会超过y个人来之前的最大值
int mx=-1,mn=INT_MAX;
int x,y,t;
cin>>x>>y;
for(int i=1;i<=x;i++)
{
scanf("%d",&t);
mx=max(t,mx);
mn=min(t,mn);
v.push_back(t);
}
//除去坐的最多的座位,能放多少个人不超过mx
int Still=0;
for(auto x:v)
Still+=mx-x;
if(Still>=y) cout<<mx<<' ';
else
{
//均分
int nowy=y-Still;
int More=ceil((double)nowy/(double)x);
cout<<mx+More<<' ';
}
cout<<mx+y<<endl;
return 0;
}

浙公网安备 33010602011771号