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 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

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 33, the Fair Nut can take 11 liter

from the first keg and 22 liters from the third keg. There are

33liters 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.

思路如下

  • 题意:跟我们n桶酒,每桶酒的体积为ar[ i ] , 然后又给我们一个杯子,问我们用这 n 桶酒倒满(有些桶里的酒可以不用)所给的杯子,在剩下的n桶酒中剩的最少体积的酒的那桶,最多可以剩多少酒。
  • 思路:直接看代码注释

题解如下

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int Len = 1005;
int ar[Len]; int main()
{
//freopen("test.txt","r",stdin);
long long int n,s;
scanf("%lld %lld",&n,&s);
long long int sum = 0; //n桶酒的总体积 for(int i = 0; i < n; i ++)
{
scanf("%d",&ar[i]);
sum += ar[i];
}
if(sum >= s)
{
sort(ar , ar + n);
long long sur = sum - ar[0] * n; //sur 为在n桶里面每桶中多余ar[0]的部分之和
if(sur >= s) //可以直接到满,直接输出最小值
{
printf("%d",ar[0]);
}
else
{
s -= sur;
long long all = n * ar[0];
all -= s;
printf("%lld",all/n);
}
}
else
cout<<-1; return 0;
}

B. Kvass and the Fair Nut的更多相关文章

  1. A - Kvass and the Fair Nut 二分

    The Fair Nut likes kvass very much. On his birthday parents presented him nn kegs of kvass. There ar ...

  2. CF1083E The Fair Nut and Rectangles

    CF1083E The Fair Nut and Rectangles 给定 \(n\) 个平面直角坐标系中左下角为坐标原点,右上角为 \((x_i,\ y_i)\) 的互不包含的矩形,每一个矩形拥有 ...

  3. CF 1083 B. The Fair Nut and Strings

    B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析:  建出trie树,给定的两个字符串就 ...

  4. CF 1083 A. The Fair Nut and the Best Path

    A. The Fair Nut and the Best Path https://codeforces.com/contest/1083/problem/A 题意: 在一棵树内找一条路径,使得从起点 ...

  5. CF1083A The Fair Nut and the Best Path

    CF1083A The Fair Nut and the Best Path 先把边权搞成点权(其实也可以不用),那么就是询问树上路径的最大权值. 任意时刻权值非负的限制可以不用管,因为若走路径 \( ...

  6. Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings

    E. The Fair Nut and Strings 题目链接:https://codeforces.com/contest/1084/problem/E 题意: 输入n,k,k代表一共有长度为n的 ...

  7. Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path

    D. The Fair Nut and the Best Path 题目链接:https://codeforces.com/contest/1084/problem/D 题意: 给出一棵树,走不重复的 ...

  8. Codeforces Round #526 (Div. 2) C. The Fair Nut and String

    C. The Fair Nut and String 题目链接:https://codeforces.com/contest/1084/problem/C 题意: 给出一个字符串,找出都为a的子序列( ...

  9. C. The Fair Nut and String 递推分段形dp

    C. The Fair Nut and String 递推分段形dp 题意 给出一个字符串选择一个序列\({p_1,p_2...p_k}\)使得 对于任意一个\(p_i\) , \(s[p_i]==a ...

随机推荐

  1. seo搜索优化技巧01-seo外链怎么发?

    在seo搜索优化中,seo外链的作用并没有早期的作用大了.可是高质量的外链对关键词的排名还是很重要的.星辉信息科技对seo外链怎么发以及seo外链建设中的注意点进行阐述. SEO外链如何做 SEO高质 ...

  2. flask 对于用户登录保持状态 flask_login

    先加载flask_login ext.py  在app下的__init__.py 进行引用把,我就不写了 login_manager = LoginManager() # 如果没有登录则重定向到该蓝图 ...

  3. Learn Regex The Easy Way

    GitHub上的正则表达式在线学习Learn Regex The Easy Way,可以帮助初学者快速入门 该项目已汉化,可在线练习 地址:https://github.com/ziishaned/l ...

  4. Vue2.0 【第二季】第1节 Vue.directive自定义指令

    目录 Vue2.0 [第二季]第1节 Vue.directive自定义指令 一.什么是全局API? 二. Vue.directive自定义指令 三.自定义指令中传递的三个参数 四.自定义指令的生命周期 ...

  5. 【5min+】 一个令牌走天下!.Net Core中的ChangeToken

    系列介绍 [五分钟的dotnet]是一个利用您的碎片化时间来学习和丰富.net知识的博文系列.它所包含了.net体系中可能会涉及到的方方面面,比如C#的小细节,AspnetCore,微服务中的.net ...

  6. (转)C++对象的内存布局

    原文地址:http://blog.csdn.net/haoel/article/details/3081328 C++ 对象的内存布局 陈皓 http://blog.csdn.net/haoel 前言 ...

  7. JS中的call()方法和apply()方法用法总结(挺好 转载下)

    最近又遇到了JacvaScript中的call()方法和apply()方法,而在某些时候这两个方法还确实是十分重要的,那么就让我总结这两个方法的使用和区别吧. 1. 每个函数都包含两个非继承而来的方法 ...

  8. pytorch的自动求导机制 - 计算图的建立

    一.计算图简介 在pytorch的官网上,可以看到一个简单的计算图示意图, 如下. import torchfrom torch.autograd import Variable x = Variab ...

  9. Alterations of brain quantitative proteomics profiling revealed the molecular mechanisms of diosgenin against cerebral ischemia reperfusion effects(大脑的定量蛋白质组学揭示了薯蓣皂苷元对脑缺血再灌注效应的分子机制)

    文献名:Alterations of brain quantitative proteomics profiling revealed the molecular mechanisms of dios ...

  10. 【转】Kerberos简介

    Kerberos协议: Kerberos协议主要用于计算机网络的身份鉴别(Authentication), 其特点是用户只需输入一次身份验证信息就可以凭借此验证获得的票据(ticket-grantin ...