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. Python - requests发送请求报错:UnicodeEncodeError: 'latin-1' codec can't encode characters in position 13-14: 小明 is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

    背景 在做接口自动化的时候,Excel作为数据驱动,里面存了中文,通过第三方库读取中文当请求参数传入 requests.post() 里面,就会报错 UnicodeEncodeError: 'lati ...

  2. 2.5D地图系统技术方案

    1.    2.5D地图概述 1.1.    概述 2.5维地图就是根据dem.dom.dlg等数据,以及真三维模型在一定高度.视角和灯光效果,按照轴侧投影的方式生成的地图.本文以臻图信息ZTMapE ...

  3. idea创建django项目

    1.环境.版本 os:windows10 ide:idea python:2.7 django:1.11.25 其他的python.django不确定这么弄会不会有其他问题. 2.python 官网下 ...

  4. linux最常用命令记录(一)

    一.vim个人最常用设置: vim .vimrc 然后添加以下内容 set nu set tabstop=4 set encoding=utf-8 二.查看磁盘空间相关命令 1.df -h   查看硬 ...

  5. Visual Studio 安装中出现闪退

    问题描述:win7 系统下, 安装 Visual Studio Community 2017 过程中,安装界面闪退 原因:Visual Studio 的版本低了 解决方案:选择 Visual Stud ...

  6. nuxt.js如何实现同级目录下建多个动态路由,并将链接设置.html后缀

    nuxt.js中如果在同级目录中建两个_xxxx.vue的动态路由文件,那么页面跳转始终是跳的一个页面,如何解决这个问题呢?下面举个栗子: 第一步:新建两个页面文件 第二步:在nuxt.config. ...

  7. session、cookie和taken的区别

    http是无状态的协议,所以要维持应用的会话形式,就需要加入以下几种机制,来进行会话跟踪,识别用户身份(当同一用户进行多次操作,不用反复请求建立新的连接,从而节省服务器资源和处理速度)   生成位置 ...

  8. Uncovering thousands of new peptides with sequence-mask-search hybrid de novo peptide sequencing framework (使用序列掩码搜索结合肽段从头测序框架发现了数千个新肽段)-解读人:刘佳维

    期刊名:Molecular & Cellular Proteomics 发表时间:(2019年12月) IF:4.828 单位: 朱拉隆功大学 费城威斯塔研究所 物种:人 技术:de novo ...

  9. [剑指offer]25.合并两个排序的链表(迭代+递归)

    25.合并两个排序的链表 题目 输入两个递增排序的链表,合并这两个链表并使新链表中的节点仍然是递增排序的. 示例1: 输入:1->2->4, 1->3->4 输出:1-> ...

  10. 几十万学费总结出来的Ddos攻击防护经验!

    本人从事网络安全行业十余年年.有十年被骗经验.被骗了很多回(都说能防300G,500G,买完就防不住了),本文当然重点给大家说明,ddos攻击是什么,中小企业如何防护,用到成本等. 言归正传 首先我们 ...