Codeforces 1084 B. Kvass and the Fair Nut

B. Kvass and the Fair Nut

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line contains two integers n

and s (1≤n≤103, 1≤s≤1012

) — the number of kegs and glass volume.

The second line contains n

integers v1,v2,…,vn (1≤vi≤109) — the volume of i

-th keg.

Output

If the Fair Nut cannot pour his glass by s

liters of kvass, print −1

. Otherwise, print a single integer — how much kvass in the least keg can be.

Examples

Input

Copy

3 3
4 3 5

Output

Copy

3

Input

Copy

3 4
5 3 4

Output

Copy

2

Input

Copy

3 7
1 2 3

Output

Copy

-1

Note

In the first example, the answer is 3

, the Fair Nut can take 1 liter from the first keg and 2 liters from the third keg. There are 3

liters of kvass in each keg.

In the second example, the answer is 2

, the Fair Nut can take 3 liters from the first keg and 1

liter from the second keg.

In the third example, the Fair Nut can't pour his cup by 7

liters, so the answer is −1.

题意:就是给你N个酒桶,每个酒桶有不同的酒,然后给你一个杯子k,问能不能倒满这个杯子,不能输出-1,能的话输出剩余酒桶中最多的为多少。

题解:一开始暴力,结果一直tle,后来发现是二分,时间不够了,实际上二分即可解决,下来又想想,发现一个巧妙思路 很简单就过了。

#include <bits/stdc++.h>
using namespace std;

const int maxx = 0x3f3f3f3f;
int main() {
	long long int n,k,a,m=maxx,s=0;
	cin>>n>>k;
	for(long long int i=0; i<n; i++) {
		cin>>a;
		m=min(m,a);
		s+=a;
	}
	if(s<k) {
		cout<<-1;
	} else {
		cout<<min(m,(s-k)/n);
	}
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值