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 ...
随机推荐
- NetworkX包
官方教程 NetworkX是一个创建,操作,研究复杂网络的结构,动态,功能的python包. #创建一个network import networkx as nx G = nx.Graph() #no ...
- Codeforces_801
A.直接暴力就行了,先把能组合的按线性组合掉,再枚举剩下相邻没用过的. #include<bits/stdc++.h> using namespace std; string s; ] = ...
- HDU_1175_莫队+逆元
http://acm.hdu.edu.cn/showproblem.php?pid=5145 初探莫队,就是离线排序后的暴力,但是效率大大提高,中间要除法取模,所以用到了逆元. #include< ...
- CCF_ 201403-2_窗口
用deque模拟. #include<iostream> #include<cstdio> #include<deque> using namespace std; ...
- Go语言实现:【剑指offer】不用加减乘除做加法
该题目来源于牛客网<剑指offer>专题. 第一步:相加各位的值,不算进位,得到010,二进制每位相加就相当于各位做异或操作,101^111. 第二步:计算进位值,得到1010,相当于各位 ...
- [redis读书笔记] 第三部分 多机数据库的实现 复制
另外一篇写的很好很深入的文章:http://www.tuicool.com/articles/fAnYFb : RDB持久化 http://www.tuicool.com/articles/F3Eri ...
- 《Head first设计模式》之工厂模式
工厂方法模式定义了一个创建对象的接口,但由子类决定要实例化的类是哪一个.工厂方法让类把实例化推迟到了子类. 预定披萨 假设你有一个披萨店,预定披萨的代码可能是这么写的: Pizza orderPizz ...
- gcc, ld
GCC gcc除了具备基本的c文件编译功能外,还把其它工具的功能也集成了进来,比如as的汇编功能,ld的链接功能. 因此,gcc也可以通过-Wa, option,将option传给汇编器as:也可以通 ...
- WLAN802.11
IEEE 802.11,1997年,原始标准(2Mbit/s,播在2.4GHz).DSSS, FHSS.该协议的一大缺点是它提供了太多的选择使得互操作性很难实现.所以它不严密,更像是一个beta标准, ...
- 5分钟看懂系列:HTTP缓存机制详解
原创文章首发于公众号:「码农富哥」,欢迎收藏和关注,如转载请注明出处! 什么是HTTP缓存 HTTP 缓存可以说是HTTP性能优化中简单高效的一种优化方式了,缓存是一种保存资源副本并在下次请求时直接使 ...