Kvass and the Fair Nut CodeForces - 1084B数学

题目
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;
}

感谢观看!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值