题目

n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.

Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?

Input

The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 109, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.

Output

Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.

Examples

Input

4 6 2

Output

2

Input

3 10 3

Output

4

Input

3 6 1

Output

3

Note

In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.

In the second example Frodo can take at most four pillows, giving three pillows to each of the others.

In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed.

题目大意

n个霍比特人排成一行准备睡觉,他们有n张床和m个枕头,弗拉多作为主人要给这些人分枕头。每个霍比特人都希望自己有尽可能多的枕头,而每个霍比特人只要比跟他相邻的人少一个以上的枕头(不包括一个),他就会受到伤害,问弗拉多在不会伤害任意一个人的情况下能获得最多多少枕头。

算法:二分 贪心

代码

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{long long n,m,k;cin>>n>>m>>k;long long low=1,high=m,mid=(low+high)/2;while(low<=high){long long sum=n+mid-1;if(mid-(k-1)>=1) sum+=(2*mid-k-2)*(k-1)/2;else sum+=(mid-2)*(mid-1)/2;if(mid-(n-k)>=1) sum+=(2*mid-3-n+k)*(n-k)/2;else sum+=(mid-2)*(mid-1)/2;if(sum>m) {high=mid-1;mid=(high+low)/2;} else {low=mid+1;mid=(high+low)/2;}} cout<<mid;return 0;
}

代码解析

从k这个位置,左右阶梯状散发,但是左右有可能很快就到头了,所以需要判断

代码中的第一个if else就是用来判断左端并且根据情况计算

相应的第二个if  else是判断右边

Frodo and pillows _CF760B相关推荐

  1. 【CodeForces - 760B 】Frodo and pillows (二分题意,注意细节)

    题干: n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row a ...

  2. Frodo and pillows CodeForces - 760B 二分 注意l和r的选择

    以后写l和r的初始值的时候,在不影响合理性的前提下,尽量写大一点 比如下面这个代码,如果r不加以或者l==0就不行 #include <iostream> #include <cst ...

  3. Codeforces Roud#393

    B. Frodo and pillows time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. DSP-SLAM:具有深度形状先验的面向对象SLAM

    点云PCL免费知识星球,点云论文速读. 文章:DSP-SLAM: Object Oriented SLAM with Deep Shape Priors 作者:Jingwen Wang Martin ...

  5. 如何征服Webpack 4并构建一个出色的React应用

    This article has been outdated with the new release for babel, kindly check the updated article &quo ...

  6. 入门深度学习,先看看三位顶级大牛Yann LeCun、Yoshua Bengio和Geoffrey Hinton的联合综述

    [编者按]深度学习领域的三位大牛Yann LeCun.Yoshua Bengio和Geoffrey Hinton无人不知无人不晓.此前,为纪念人工智能提出60周年,Yann LeCun.Yoshua ...

  7. 中石油计算机职称考试题,2019年职称英语考试中石油历年真题及答案

    I. Vocabulary Directions: There are 20 incomplete sentences in this part. For each sentence there ar ...

  8. linux添加美式键盘,win8\win server 2012添加【中文--美式键盘】

    关于div的居中的问题 (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-01-11) div水平和垂直居中,text-align和vertical-align不起作用,因为标 ...

  9. CVPR2020检测类论文最全汇总:136篇论文方向细分(附代码和论文打包下载)

    为了方便大家进一步的学习,我们对这CVPR中的1467篇论文进行了整理,本次分享的是所有检测类论文,并将它们细分为3D目标检测.人脸检测.动作检测.视频目标检测.文本检测.行人检测等方向,同时附上了相 ...

  10. 《Nature》纪念人工智能60周年专题:深度学习综述

    来源:网络大数据 摘要:本文是<Nature>杂志为纪念人工智能60周年而专门推出的深度学习综述,也是Hinton.LeCun和Bengio三位大神首次合写同一篇文章. 本文是<Na ...

最新文章

  1. Oracle隐含参数:_allow_resetlogs_corruption
  2. 我又发现了7个让人心动的宝藏软件,很少有人知道
  3. vue打包后element-ui部分样式(图标)异常问题
  4. Delphi和C++数据类型对照表
  5. 自定义类型处理器的应用
  6. 后端开发 java_Java后端开发三年,你不得不了解的JVM
  7. 【001:这条路很漫长,但出发了就不要想还有多远】
  8. docker私有仓库Harbor 使用文档
  9. 2011年12月份第一周51Aspx源码发布详情
  10. 对象新增方法 object.is() object.assign()
  11. libaio在mysql中的作用,ubuntu安裝mysql遇到的坑----解決Mysql報錯缺少libaio.so.1
  12. 怎么删除远程桌面连接IP记录 删除连接信息
  13. linux线程 ppt,实验十七Linux下进程线程的创建.ppt
  14. 完美卸载itunes
  15. 逻辑左移、算术左移、逻辑右移、算术右移
  16. GEE学习记录~~~
  17. 如何在mac上使用虚拟机中的oracle
  18. 用cJSON解析心知天气返回的数据包
  19. 爬虫学习实践(1)——我的第一个小爬虫
  20. IntelliJ IDEA设置编码格式

热门文章

  1. 并行计算、分布式计算、集群计算和网格计算的介绍,以及主要有哪些区别?
  2. 电商运营分享:关于双11的淘宝客无节操赚钱干货
  3. Ireport 子报表分页
  4. bash ps1变量_Linux:设置用户变量ps1
  5. 安全渗透测试工具--Burpsuite的爬虫功能
  6. 让我们自己来破解命运外挂999
  7. QX2601液晶手写板擦写板专用IC芯片
  8. Excel数据分析(八)图表
  9. python中value的含义_python中value的意思
  10. 三维分子模型软件PyMOL