A - 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
3 3
4 3 5
3
3 4
5 3 4
2
3 7
1 2 3
-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.
#include <cstdio>
#include <iostream> using namespace std; long long v[]; int main()
{
long long n;
long long s;
scanf("%lld %lld",&n,&s);
for(int i=;i<n;++i)
{
scanf("%lld",&v[i]);
} long long min_v=v[];
for(int i=;i<n;++i)
{
if(min_v>v[i])
{
min_v=v[i];
}
} long long sum=;
for(int i=;i<n;++i)
{
sum+=v[i]-min_v;
} long long left=,right=min_v,k=-; while(left<=right)
{
long long mid=(left+right)>>;
if(sum+(min_v-mid)*n >= s)
{
k=max(mid,k);
left=mid+;
}
else
{
right=mid-;
}
} printf("%d\n",k); return ;
}
A - Kvass and the Fair Nut 二分的更多相关文章
- 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 sta ...
- CF1083E The Fair Nut and Rectangles
CF1083E The Fair Nut and Rectangles 给定 \(n\) 个平面直角坐标系中左下角为坐标原点,右上角为 \((x_i,\ y_i)\) 的互不包含的矩形,每一个矩形拥有 ...
- CF 1083 B. The Fair Nut and Strings
B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析: 建出trie树,给定的两个字符串就 ...
- 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 题意: 在一棵树内找一条路径,使得从起点 ...
- CF1083A The Fair Nut and the Best Path
CF1083A The Fair Nut and the Best Path 先把边权搞成点权(其实也可以不用),那么就是询问树上路径的最大权值. 任意时刻权值非负的限制可以不用管,因为若走路径 \( ...
- 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的 ...
- 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 题意: 给出一棵树,走不重复的 ...
- 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的子序列( ...
- 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 ...
随机推荐
- 在form子句中使用子查询时的注意事项
今天中午为了弄清这个问题,本人真的是头都搞大了!最后明白了一点,在from子句中使用子查询是,一定要将临时表的别名带上,否则会灰常痛苦!!!
- codeforces 1020 C Elections(枚举+贪心)
题意: 有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元.你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派. n,m<3000 思路 ...
- 从Golang中open的实现方式看Golang的语言设计
Golang有很多优点: 开发高效:(C语言写一个hash查找很麻烦,但是go很简单) 运行高效:(Python的hash查找好写,但比Python高效很多) 很少的系统库依赖:(环境依赖少,一般不依 ...
- 使用bisect库实现二分查找
手动实现 假如有一个有序表nums,怎么样在nums里找到某个值的位置呢?没错,就是nums.index(k),哈哈哈哈哈哈哈-- 假如nums很长很长,那就要祭出二分查找了 def binary_s ...
- 10-SpringMVC04
FreeMarker 1.入门案例 1. 导包:freemarker.jar 2. 需要创建模板文件的路径:src/main/resources/template 3. 创建一个模板对象:hello. ...
- Linux中awk抽取包含某字段的整行日志
命令示例:awk '{if($0~"listAuths") print}' xxx.log 解释说明:抽取xxx.log整个日志文件中,包含“listAuths”的行,打印输出
- zabbix流量过大就断图
监控内网千兆交换机,流量图断断续续,大概位于400-500兆就会断图,而且还不准. 按照这个操作几乎可以成功 链接:http://itfish.net/article/23536.html h ...
- linux中的特殊符号及其含义梳理
1. 重定向符号及含义 注意:箭头流向即是数据的流向. 数字0:标准输入(standard input,简写stdin),数据从右往左方向流动 数字1:标准正确输出(standard output,简 ...
- mqttnet3.0用法
.net常用的mqtt类库有2个,m2mqtt和mqttnet两个类库 当然了,这两个库的教程网上一搜一大把 但mqttnet搜到的教程全是2.7及以下版本的,但3.0版语法却不再兼容,升级版本会导致 ...
- 2020-2-27今日总结——滚动监听&导航
利用Bootstrap 开发工具实现滚动监听 (此文只做学习路上的归纳分享总结用,如有侵权,请联系我删除) 使用滚动监听,比较特殊,要在body中设置scroll,以及触点. 很好理解,因为滚动是多对 ...