B. Frodo and pillows

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

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 nm 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.

以k位置为中心,枕头数量向两侧递减。二分搜索答案。

 //2017.01.31
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int n, m, k;
while(cin>>n>>m>>k)
{
m -= n;
long long lp = k-, rp = n-k;
long long l = , r = m, mid, ans;
while(l<=r)
{
mid = (l+r)>>;
long long tmp = mid;
if(mid>=lp)tmp += (mid*-lp-)*lp/;
else tmp += (mid-)*mid/;
if(tmp > m){r = mid-;continue;}
if(mid>=rp)tmp += (mid*-rp-)*rp/;
else tmp += (mid-)*mid/;
if(tmp < m){
ans = mid+;
l = mid+;
}
else if(tmp > m)r = mid-;
else{
ans = mid+;
break;
}
}
cout<<ans<<endl;
} return ;
}

CodeForces760B的更多相关文章

随机推荐

  1. jzoj4424

    20%:暴力枚舉每一條邊有沒有被選到,然後使用并查集判斷聯通性 這樣子有20分,但是我考試寫掛了所以1分也沒有 100%:這道題2000的數據範圍,使用指數級搜索會tle,需要更加好的方法 這道題中, ...

  2. centos6.5 yum安装lamp

    准备篇: 1.清空防火墙 iptables -F 或者关闭防火墙 /etc/init.d/iptables stop,如果要防火墙开机不要启动 chkconfig iptables off 2.关闭S ...

  3. Myeclipse中java项目转成Web项目

    在eclipse导入一个myeclipse建的web项目后,在Eclipse中显示的还是java项目,按下面的步骤可以将其转换成web项目. 1.找到项目目录下的.project文件 2.编辑.pro ...

  4. request.getParameter("name")获取参数为null和空字符串的区别

    1.获取到的值为空字符串 当url里有name属性,但是没有值的时候,后台用request.getParameter("name")获取到的是空字符串 2.获取到的值为null 当 ...

  5. Swinject 源码框架(二):循环依赖的解决

    可能存在循环依赖,比如 Parent 强制有 Child, Child 弱持有 Parent. 具体实现如下.Parent 初始化时,必须传入 Child,而 Child 初始化不必传入 Parent ...

  6. 转MVC3介绍

    第一节:Asp.Net MVC3项目介绍 让我们先看一下,一个普通的Asp.Net MVC3项目的样例,如下图所示 跟WebFrom还是有区别的,如果你已经了解Asp.Net MVC2的话,那就感觉异 ...

  7. JavaScript父子页面之间的相互调用

    父页面: <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>< ...

  8. vba调用c#dll

    本文阐述如何用C#创建COM组件,并能用VB6.0等调用.附有完整测试通过的代码.该功能总体看来很简单,实际值得注意的地方还是挺多.因为很少有人写这类文章,有些代码也是转来转去的不全,有些甚至让人误入 ...

  9. 【jQuery源码】事件委托

    jQuery的事件绑定有几个比较优秀的特点: 1. 可以绑定不限数量的处理函数 2. 事件可以委托到祖先节点,不必一定要绑到对应的节点,这样后添加的节点也照样能被处理. 3. 链式操作 下面主要分析事 ...

  10. fail2ban的使用以及防暴力破解与邮件预警

    fail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是防火墙),而且可以发送e-mail通知系统管理员! fail2ban运行机制:简单来说其功能就 ...