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. collectd+influxdb+grafana

    今天一天都在弄这个,最终发现在配置grafana的时候选择influxdb的版本时候选错了.(挠头~~~!!!) collectd的配置还算简单,基本看过配置文件就比较清楚. influxdb(Go ...

  2. 【小程序云开发入门】quickStart

    开发者可以使用云开发开发微信小程序.小游戏,无需搭建服务器,即可使用云端能力. 云开发为开发者提供完整的云端支持,弱化后端和运维概念,无需搭建服务器,使用平台提供的 API 进行核心业务开发,即可实现 ...

  3. django -orm操作总结

    前言 Django框架功能齐全自带数据库操作功能,本文主要介绍Django的ORM框架 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MyS ...

  4. day 34 js 基础后部分 BOM 和 事件和正则

    前情提要 今天主要学习的是bom 和事件 一:正则表达式 <!DOCTYPE html> <html lang="en"> <head> < ...

  5. swift 3.0 正则表达式查找/替换字符

    1.什么是正则表达式 正则表达式,又称正规表示法.常规表示法(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式使用单个字符 ...

  6. POJ 1067

    #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> usin ...

  7. VS2013创建Windows服务与调试服务

    1.创建Windows服务 说明: a)Description 服务描述,直接显示到Windows服务列表中的描述: b)DisplayName 服务显示名称,直接显示到Windows服务列表中的名称 ...

  8. 查看LINUX 系统硬件等详细信息

    转载这位朋友[地址] 几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) mor ...

  9. 《LeetBook》leetcode题解(18) : 4Sum[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  10. databinding在android studio2.3版本后不再默认支持使用

    databinding在android studio2.3版本后不再默认支持使用,需要在项目的app-build-gradle的 dependencies 里面添加 apt 'com.android. ...