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. docker 学习(四)

    1.Dockerfile简介 1)什么是Dockerfile Dockerfile是一个包含用于组合映像的命令的文本文档.可以使用在命令行中调用任何命令. Docker通过读取Dockerfile中的 ...

  2. [2020.03]Unity ML-Agents v0.15.0 环境部署与试运行

    一.ML-Agents简介 近期在学习Unity中的机器学习插件ML-Agents,做一些记录,用以简单记录或交流学习. 先简单说一下机器学习使用的环境场景:高视觉复杂度(Visual Complex ...

  3. php判断二个数最大公约数

    $m = isset($_GET['m']) ? $_GET['m'] : 12; $n = isset($_GET['n']) ? $_GET['n'] : 8; //判断mn的大小 if($m&g ...

  4. django 从零开始 4 404页面和500页面设置

    在视图函数中定义两个 函数 分别对应404 个500页面 (自定义html内容吧,这里只是展示) 在template页面指向自己定义的404.html和500.html页面 在项目的urls中设置 h ...

  5. 探究Spring Boot中的接收参数问题与客户端发送请求传递数据

    结合此篇参考Spring框架学习笔记(9)--API接口设计相关知识及具体编码实现 在使用Spring Boot进行接收参数的时候,发现了许多问题,之前一直都很忙,最近才稍微有空研究一下此问题. 网上 ...

  6. css hover 动画 transition:background-color 0.2s,color 0.2s; 外层套内层,正常是 里外层 鼠标上来 外层有hover,如果就想到里层hover触发外层hover,要用外层position 定义绝对定位,内层的hover跳出外层的div,这样视觉上就是两个单独的div,进行内外层联动。

    css hover 动画 transition:background-color 0.2s,color 0.2s; 外层套内层,正常是 里外层 鼠标上来 外层有hover,如果就想到里层hover触发 ...

  7. Python - 面向对象(三)公共变量,受保护变量,私有变量

    前言 在Python的类里面,所有属性和方法默认都是公共的:但Python也可以设置受保护.私有类型的变量or方法 受保护类型的变量.方法 一般称为:protected变量 #!/usr/bin/en ...

  8. Redis基本数据类型、数据持久化、过期策略及淘汰机制

    一点技术.技术乐享!!! 如果有人问你:Redis这么快,他的“多线程模式”你了解吗? 请回答他:您是想问Redis这么快,为什么还是单线程模式吗? redis是什么 简单来说redis是C语言开发的 ...

  9. GO语言web框架Gin之完全指南(二)

    这篇主要讲解自定义日志与数据验证 参数验证 我们知道,一个请求完全依赖前端的参数验证是不够的,需要前后端一起配合,才能万无一失,下面介绍一下,在Gin框架里面,怎么做接口参数验证的呢 gin 目前是使 ...

  10. PowerShell初探

    Windows PowerShell是一种命令行外壳程序和脚本环境,它内置在每个受支持的Windows版本中(Windows 7/Windows 2008 R2和更高版本),使命令行用户和脚本编写者可 ...