题目:http://codeforces.com/problemset/problem/1042/A

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mid ((l+r)>>1)
using namespace std;
int const maxn=;
int n,m,a[maxn],ans,mx;
bool ck(int x)
{
int ret=;
for(int i=;i<=n;i++)ret+=x-a[i];
return (ret>=m);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%d",&a[i]),mx=max(mx,a[i]);
int l=mx,r=mx+m;
while(l<=r)
{
if(ck(mid))ans=mid,r=mid-;
else l=mid+;
}
printf("%d %d\n",ans,mx+m);
return ;
}

CF 1042 A Benches —— 二分答案(水题)的更多相关文章

  1. Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  2. CF 1042A Benches——二分答案(水题)

    题目:http://codeforces.com/problemset/problem/1042/A #include<iostream> #include<cstdio> # ...

  3. AT2165 Median Pyramid Hard 二分答案 脑洞题

    无论再来多少次也不可能想到的写法. 二分一个最小的顶端值\(k\),大于设为\(1\)小于等于设为\(0\),可以证猜出来(你跟我说这可以?)如果存在两个连在一起的0/1那么它们会一直往上跑,还可以很 ...

  4. CF 332A Down the Hatch! 超级水题。。不过题目太长了

    A. Down the Hatch! time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. CF 949 D Curfew —— 二分答案

    题目:http://codeforces.com/contest/949/problem/D 先二分一个答案,让两边都至少满足这个答案: 由于越靠中间的房间越容易满足(被检查的时间靠后),所以策略就是 ...

  6. UVa 11636 - Hello World! 二分,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. CF 1008B Turn the Rectangles(水题+贪心)

    There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it ...

  8. BZOJ 4590 [Shoi2015]自动刷题机 ——二分答案

    二分答案水题. #include <cstdio> #include <cstring> #include <iostream> #include <algo ...

  9. Luogu P2920 时间管理【二分答案】

    二分答案水题. (像我这么蒻的人都能十几分钟A掉) https://www.luogu.org/problemnew/show/P2920 开始时间一定在从0到min(t[i]-s[i])的一段区间上 ...

随机推荐

  1. kvm:日常使用

    常用命令 创建新镜像:qemu-img create -f qcow2 /var/lib/libvirt/images/$1.img 100G 创建新镜像:qemu-img create -f qco ...

  2. Python和Java的语法对比,语法简洁上python的确完美胜出

    Python是一种广泛使用的解释型.高级编程.通用型编程语言,由吉多·范罗苏姆创造,第一版发布于1991年.可以视之为一种改良(加入一些其他编程语言的优点,如面向对象)的LISP.Python的设计哲 ...

  3. LeetCode(36)Valid Sudoku

    题目 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  4. jz2440开发板烧写裸板

    前提:手头没有openjtag,电脑上没有并口, 实现方法:jlink下载,nor上的uboot下载 关键点是用jlink下载uboot 1,使用jlink进行烧写,其中注意的是jlink只能烧写no ...

  5. Spring 和 Hibernate的整合

    问题 ,spring 和 hibernate 整合 如何整合 1. Spring 使用Hibernate的的SessionFactory 2. Hibernate使用Spring提供的声明式事务

  6. 新装mvn建第一个项目报错org.apache.maven.plugins:maven-resources-plugin:2.6

    1.第一次创建mvn项目会报maven-resources-plugin-2.6.jar错,原因是mvn无法自动下载这个jar包,多次删除这个目录下的C:\Users\Administrator\.m ...

  7. Linux下C编程入门(7)

    Linux下项目同步工具介绍git和github 一.远程仓库工具github 1. 一.本地操作工具git 1.

  8. 洛谷—— P1690 贪婪的Copy

    https://www.luogu.org/problem/show?pid=1690 题目描述 Copy从卢牛那里听说在一片叫yz的神的领域埋藏着不少宝藏,于是Copy来到了这个被划分为个区域的神地 ...

  9. noi.openjudge——8465 马走日

    http://noi.openjudge.cn/ch0205/8465/ 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  1024kB 描述 马在中国象棋以日字形规则移动. 请编写 ...

  10. 洛谷 P1404 平均数

    P1404 平均数 题目描述 给一个长度为n的数列,我们需要找出该数列的一个子串,使得子串平均数最大化,并且子串长度>=m. 输入输出格式 输入格式: N+1行, 第一行两个整数n和m 接下来n ...