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.

Example
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<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define LL long long int
const LL INF = 1e9 + 5;
int n, m, k;
LL Sum(LL a, LL b)
{if (b == 0)return  0;LL tmp=min(a,b);//LL tmp2 = max(a, b);tmp = (a*2-tmp+1)*tmp / 2;return tmp;
}
bool check(LL tmp)
{LL p, q,ans=0;p = k - 1;//Lq = n - k + 1;//Rif (p < 0)p = 0;if (q < 0)q = 0;ans += Sum(tmp-1,p) + Sum(tmp,q);if (ans <= m){return 1;}return 0;
}
int main()
{   while (cin >> n >> m >> k){LL L = 0, R = INF, mid;m -= n;//L+1while (L < R){mid = (L + R) / 2;if (check(mid)){L = mid+1;}else{R = mid;}}cout << L << endl;}return 0;
}

D - Frodo and pillows CodeForces - 760B相关推荐

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

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

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

  3. Codeforces Roud#393

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

  4. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  5. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  6. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  7. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  8. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  9. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  10. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

最新文章

  1. android NinePatch图片制做
  2. 《计算机组成与设计(ARM版)》读书笔记-第二章指令2
  3. java 中while编译之后_从APK反编译的Java-while循环什么也不做
  4. $JavaScript(3)
  5. 有关 Lambda linq练习 有待整理
  6. Eclipse项目无错误但是有红叉问题解决
  7. php期末作业经验,期末作业.php
  8. Java垃圾回收GC概览
  9. Linux: Shared MIME
  10. iOS 使用UIView的一种有效方法
  11. 分布式存储系统学习笔记(二)—分布式文件系统(1)—Google文件系统GFS
  12. Python中,如何使用ImageDraw在Image上绘制粗线?
  13. pyqt 子窗口控制主窗口绘图_PyQtGraph如何关闭绘图窗口/关闭所有绘图窗口?
  14. python函数中文手册-python函数手册
  15. 单机倒立摆系统建模与仿真
  16. 清华大学团队:人脸识别爆出巨大丑闻,15分钟解锁19款手机
  17. fragstats教程
  18. 今天看到标题 《 章子怡低胸礼服亮相(组图)》
  19. python中使用“[函数名].[变量名]”声明变量
  20. 使用MSHTML解析HTML代码

热门文章

  1. 一种电池过放电保护电路
  2. 不要STUPID,坚持GRASP和SOLID
  3. rust倒地了怎么起来_ggxx出招表
  4. ubuntu samba Windows共享 你可能没有权限访问网络资源
  5. LeetCode 5855. 找出数组中的第 K 大整数(自定义排序函数)
  6. Autumn Web Handler
  7. 小学计算机反思案例,小学教师教育事案例以及反思
  8. 怎么在电脑设置html,电脑怎么定时开机
  9. 网易云解锁配置(windows)
  10. 汇编语言--微机CPU的指令系统(五)(循环指令)