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 ...
随机推荐
- 快速上手 Python 命令行模块 Click
关于Click? 说下 Click 模块是干啥的,简单说,它就是把我们的 Python 脚本的一些函数,通过 添加带有 Click 关键字的装饰器进行装饰进而将函数调用的形式转化为命令行传参的形式然后 ...
- 面试官系统精讲Java源码及大厂真题系列之Java线程安全的解决办法
1. 背景 1.1 static修饰类变量.方法.方法块. public + static = 该变量任何类都可以直接访问,而且无需初始化类,直接使用 类名.static 变量 1.2 多个线程同时 ...
- C语言程序设计(二) C数据类型
第二章 C数据类型 八进制整数由数字0开头,后跟0~7的数字序列组成. 十六进制整数由数字0加字母x(或X)开头,后跟0~9,a~f(或A~F)的数字序列组成. 整型常量: 默认的int型定义为有符号 ...
- golang sms阿里云发送短信(公司实际项目)
话不多说,直接上代码!!! 要先下载两个包 (可以go get -u +你想要的包) github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests githu ...
- Vue2.0 【第一季】第2节 v-if v-else v-show 指令
目录 Vue2.0 [第一季]第2节 v-if v-else v-show 指令 第二节 v-if v-else v-show 指令 2.1 v-if指令.v-else指令: 2.2 v-show的使 ...
- vscode 新版设置备份20200221 settings.json
vscode 新版设置备份20200221 { "sync.gist": "9e6a5f7e8c52047b03c8732ff88aab0e", "s ...
- JVM的组成
JVM一共有五大区域,程序计数器.虚拟机栈.本地方法栈.Java堆.方法区. 程序计数器 程序技术器是一块很小的内存空间,由于Java是支持多线程的.当线程数大于CPU数量时,CPU会按照时间片轮寻执 ...
- 阅读GitHub源码的正确打开方式
前言 近来发现阅读开源项目上手就整最新的代码不合适,缺少项目迭代的具体实现过程,想着若是可以看到针对问题的提交代码就好了,所以就有了本篇博客. 以文主要涉及:如何fork开源项目,如何保证本地仓库代码 ...
- Asp.net Repeater控件的绑定与操作
由于repeater 控件具有的一个特性--循环 <ItemTemplate>的内容,Repeater 控件里的某个元素对象的绑定与获取,不像平常的,直接使用控件的 id 便可以给该控件进 ...
- 网络安全从入门到精通(第二章-3)后端基础SQL— MySQL高级查询与子查询
本文内容: MySQL的基础查询语句 链接查询 联合查询 子查询 渗透测试常用函数 1,MySQL基础查询语句: select * from 表 order by ASC/DESC; ASC:从小到 ...