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 ...
随机推荐
- CCF_201509-1_数列分段
水. #include<iostream> #include<cstdio> using namespace std; int main() { ]; cin >> ...
- Ops:命名规范
前言 好的命名规范见名知义,可以极大的提高工作效率,对于运维工作的标准化至关重要,这里,分享本DevOps小组内讨论的命名规范,希望有参考意义,如果小伙伴们有好的建议或补充,欢迎留言. 1. ansi ...
- 【CMake】CMake GUI构建VS等项目
一.CMake官网(https://cmake.org/)上的介绍: CMake is an open-source, cross-platform family of tools designed ...
- ElasticSearch基础入门学习笔记
前言 本笔记的内容主要是在从0开始学习ElasticSearch中,按照官方文档以及自己的一些测试的过程. 安装 由于是初学者,按照官方文档安装即可.前面ELK入门使用主要就是讲述了安装过程,这里不再 ...
- 从敏捷开发到微服务,maybe再到中台
-- 先说下准备这个的背景: 本来是想让我分享下敏捷开发,可能是听我说为as**搭建并完善了敏捷开发体系的原因吧. 我一般分享一个东西,希望大家能真的理解,而不只是知道. 我不大相信有万能的东西,不希 ...
- Coroutine 预激装饰器
预激装饰器 讨论如何终止协程之前,我们要先谈谈如何启动协程.使用协程之前必须预激,可是这一 步容易忘记.为了避免忘记,可以在协程上使用一个特殊的装饰器.接下来介绍这样一个 装饰器. 预激协程的装饰器, ...
- pytorch之 RNN classifier
import torch from torch import nn import torchvision.datasets as dsets import torchvision.transforms ...
- 修改定时清理 /tmp 目录下的文件
初衷 默认系统是超过 30 天不访问的文件自动清除的,但是有时候硬盘用得紧可以考虑修改周期 设置方法 编辑配置文件:vim /etc/cron.daily/tmpwatch #! /bin/sh fl ...
- vsphere 客户机 使用光驱引导启动
vsphere上的虚拟服务器 需要用光盘引导启动,用pe系统做维护. 第一部:光盘ios文件 存放的位置 可以直接放光盘 或者将ios文件放到数据存储中 或者将ios文件放到实体主机的存储内 ...
- Linux ftp VSftp
一.Linux FTP服务器分类: <1>wu-ftp <2>proftp=profession ftp <3>vsftp=very security ftp 本 ...