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
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的更多相关文章
- 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 ...
- 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 ...
随机推荐
- 关于在layui中的table checkbox 默认选中设置
一.layui版本 layui-v2.4.5 二.设置table的checkbox默认选中 总共有两种方法: 方法1:在返回的json中设置LAY_CHECKED为true,页面上的checkbox就 ...
- Eclipse与MyEclipse的联系和区别
Eclipse与MyEclipse的联系和区别 Eclipse 是一个IDE(Integrated Developing Environment),而这个IDE是允许安装第三方开发的插件来使自身的功 ...
- spring boot 过滤器 前后端分离跨域sessionId不一致
import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.http ...
- 初探Linux
这是一个小小新手根据自己对Linux的理解而写下的笔记,记录的是大体的学习内容.记录的笔记不全面,甚至没有整体的概念,但也希望能够给部分人一些入门的帮助,实机基于CentOS 7. 导语:学习一件新事 ...
- docker 编译开发代码做镜像
文件目录 Dockerfile 是docker制作镜像的文件,docker_run.sh是sh文件,gin_test是go编译之后的linux可执行程序,gintest.env是配置文件夹 首先写一个 ...
- vue 父子组件 基础应用scrollball v-model sync
# 组件之间通信 可以通过 v-model 子组件可以通过 改变数据来改变父组件的数组 * v-model 子组件需要接受value属性,需要出发this.$emit("input&qu ...
- html5特性简要概括
1.html5主要的设计目的: 互联网语义化,以便更好地被人类和机器阅读 更好的在移动设备上支持web应用 https://www.w3.org/TR/html5 新增内容: 新的语义标签 <h ...
- H5解决安卓软键盘弹出遮蔽的方法
首先先判断是否为安卓,是的话才添加事件监听,获取焦点元素判断是否为input或者textarea类型,是的话,Element.scrollIntoView() 方法会让当前的元素滚动到浏览器窗口的可视 ...
- rbac权限+中间件 初识
rbac权限+中间件 1.权限组件rbac 1.什么是权限 1 项目与应用 2 什么是权限? 一个包含正则表达式url就是一个权限 who what how ---------->True or ...
- MySQL数据库升级
当前不少系统的数据库依旧是MySQL5.6,由于MySQL5.7及MySQL8.0在性能及安全方面有着很大的提升,因此需要升级数据库.本文通过逻辑方式.物理方式原地升级来介绍MySQL5.6 升级至M ...