[codeforces 760B]Frodo and pillows

time limit per test : 1 second
memory limit per test : 256 megabytes

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 ≤ 10^9, 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

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

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

3.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个人,m个枕头,主角躺在第k张床上。每个人睡觉都至少要有一个枕头,如果一个人和他相邻的一个人使用的枕头数相差2个或以上,那么他就会感到伤心,求问在保证所有人都不伤心的情况下,主角最多能使用多少个枕头。

题解:(我觉得 这种题目我都想得吃力,已经可以弃疗了。。)
首先先给每个人分配一个枕头,然后答案先记成1。我们可以知道,把主角设成最高点,然后向两边递减就可以得出答案。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define LiangJiaJun main
using namespace std;
int n,m,k,ans=1,Reduc_;

int LiangJiaJun(){
    scanf("%d%d%d",&n,&m,&k);
    m -= n;
    Reduc_ = 1;
    if(m == 0) return puts("1"),0;
    while(m>0){
        if(k+ans<=n)++Reduc_;
        if(k-ans>=1)++Reduc_;
        m -= Reduc_;
        ++ans;
    }
    printf("%d\n",ans);
    return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值