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

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
ll count,n,m,k,ans,pos,cnt,inf;
while(scanf("%I64d%I64d%I64d",&n,&m,&k)!=EOF)
{
cnt=;count=;inf=;
m-=n;ans=;
pos=max(k-,n-k);
for(ll i=;i<=pos;i++)
{
cnt+=(i*-);//交替铺最多消耗枕头数
}
if(m>cnt)//平铺
{
inf=(m-cnt)/n;
m-=(inf*n);
}
while(m>)//交替铺
{
if(k-count>=) ans++;
if(k+count<=n) ans++;
m-=ans;
count++;
}
printf("%I64d\n",inf+count);
}
return ;
}

最新文章

  1. 代码提交的时候可以插入表情了-GitHub表情的使用
  2. java单例模式详解
  3. (4) 二叉平衡树, AVL树
  4. 项目总结笔记系列 Maven Session2
  5. SQL增强之Merge
  6. LightSpeed 之Sql和存储过程的使用
  7. PHP 页面编码声明方法详解(header或meta)
  8. Win7下MongoDB安装
  9. Elasticsearch是一个分布式可扩展的实时搜索和分析引擎,elasticsearch安装配置及中文分词
  10. Linux下打包压缩成war包和解压war包
  11. Android基础学习之context
  12. Zepto.js touch模块深入分析 解决手机点击事件
  13. 【转】Android 4.3源码下载及问题解决
  14. hive语句嵌入python脚本(进行map和reduce,实现左外连接)
  15. C# Interview Question 1
  16. HBase中此类异常解决记录org.apache.hadoop.ipc.RemoteException(java.io.IOException):
  17. day14 装饰器模拟验证附加功能
  18. 一、GPIO操作
  19. Java中的ReentrantLock和synchronized两种锁定
  20. Redis源码学习-Master&amp;Slave的命令交互

热门文章

  1. cocos2d-js导弹跟踪算法(一边追着目标移动一边旋转角度)
  2. HDU 3555 Bomb(数位DP模板啊两种形式)
  3. codeforces 701 B. Cells Not Under Attack
  4. 不允许 ASSIGNMENT 语句中包含 FOR XML 子句。
  5. Svn备份与Bandizip压缩批处理程序
  6. vue+ webpack中的animate.css实现的执行多个连续的动画
  7. shell脚本的if判断语句
  8. ReadyAPI/soapUI发送post请求json格式(带有中文字符),后台获取参数为空
  9. cogs 1396. wwww
  10. AES加密解密&amp;amp;&amp;amp;SHA1、SHA加密&amp;amp;&amp;amp;MD5加密