题目
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are vi liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it’s not possible to pour his glass by s liters of kvass.
题意:
有n桶格瓦斯(知道每桶的量)还有一个容器s。
把格瓦斯倒进s,到不满输出-1
能到满 :求出剩下桶中格瓦斯最小的量
题解:
就看能不能用到最后一个桶(量最少的哪一个),如果还没用到它s就填满了,那最小的就是最后一个,如果用得到,那就直接取平均数
代码:
#include<iostream>
#define ll long long
using namespace std;
int main()
{
ll n,s,sum=0,mint=99999999;
cin>>n>>s;
for(int i=0;i<n;i++)
{
ll t;
cin>>t;
mint=min(mint,t);
sum+=t;
}
if(sum<s)
cout<<-1<<endl;
else
cout<<(min(mint,(sum-s)/n))<<endl;
return 0;
}
感谢观看!