Codeforces Round #526 (Div. 2) B

                                                                              B. Kvass and the Fair Nut

The Fair Nut likes kvass very much. On his birthday parents presented him nn kegs of kvass. There are vivi liters of kvass in the ii-th keg. Each keg has a lever. You can pour your glass by exactly 11 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by ss 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 ss liters of kvass.

Input

The first line contains two integers nn and ss (1≤n≤1031≤n≤103, 1≤s≤10121≤s≤1012) — the number of kegs and glass volume.

The second line contains nn integers v1,v2,…,vnv1,v2,…,vn (1≤vi≤1091≤vi≤109) — the volume of ii-th keg.

Output

If the Fair Nut cannot pour his glass by ss liters of kvass, print −1−1. Otherwise, print a single integer — how much kvass in the least keg can be.

Examples

input

3 3
4 3 5

output

3

input

3 4
5 3 4

output

2

input

3 7
1 2 3

output

-1

Note

In the first example, the answer is 33, the Fair Nut can take 11 liter from the first keg and 22 liters from the third keg. There are 33 liters of kvass in each keg.

In the second example, the answer is 22, the Fair Nut can take 33 liters from the first keg and 11 liter from the second keg.

In the third example, the Fair Nut can't pour his cup by 77 liters, so the answer is −1−1.

题意:总结下来就是从所有桶中取出的酒为s,求所有有桶中剩下的最小的最大为多少,比如,这里有[5,6,4],要取出4升酒,那就会有[1,6,4], [5,2,4], [5,6,0]这不同的情况,对应的最小值分别为1, 2, 0。然而这些都不如[4,4,3]的最小值大,所以结果是3。暴力是肯定会挂的。(读题真的好累啊)

 

#include<iostream>
#include<memory.h> 
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
ll n, s;
ll v[maxn];
int main()
{
	ll mi = 1e9+1, ans = 0, cnt = 0;
	scanf("%lld%lld", &n, &s);
	for(int i = 1;i <= n;i ++)
		scanf("%lld", &v[i]);
	mi = *min_element(v + 1, v + n + 1);
	for(int i = 1;i <= n;i ++)
	{
		if(v[i] > mi)
		{
			cnt += v[i] - mi;		//先将大于最小值的差值加起来 
		}
	}
	ans = mi;						//表示现在所有桶里的最小值 
	if(ans * n + cnt < s)			//所有桶的酒量不足 
	{
		cout << "-1" << endl;
		return 0;
	}
	if(cnt >= s)					
	{
		cout << ans << endl;
		return 0;
	}
	if((s - cnt) % n == 0)
		cout << ans - (s - cnt) / n << endl;
	else
		cout << ans - (s - cnt) / n - 1 << endl;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值