CF760B.Frodo and pillows

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

有 nn 个霍比特人计划在弗罗多家过夜。弗罗多有排成一排的 nn 张床和 mm 个枕头(满足 n≤mn \leq m)。每个霍比特人都需要一张床和至少一个枕头才能睡觉,但每个人都希望尽可能多地获得枕头。当然,枕头并不总能被均分,然而,如果某个霍比特人拥有的枕头数比他的任意一位邻居少至少两个,他就会感到受伤。

弗罗多将睡在从左往右数第 kk 张床上。在满足以下条件的前提下:每个霍比特人都至少获得一个枕头、所有枕头都必须分配给某个霍比特人、且没有任何霍比特人受伤,弗罗多最多能拥有多少个枕头?

输入格式

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.

唯一的一行包含三个整数 nn、mm 和 kk(1 ≤ n ≤ m ≤ 1091 ≤ n ≤ m ≤ 10^9,1 ≤ k ≤ n1 ≤ k ≤ n)—— 分别表示霍比特人的数量、枕头的总数以及弗罗多床的编号。

输出格式

Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.

输出一个整数——佛罗多最多能拥有的枕头数量,使得没有人受到伤害。

输入输出样例

  • 输入#1

    4 6 2

    输出#1

    2
  • 输入#2

    3 10 3

    输出#2

    4
  • 输入#3

    3 6 1

    输出#3

    3

说明/提示

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.

在第一个例子中,弗罗多最多可以拥有两个枕头。此时,他可以给第一张床上的霍比特人两个枕头,给第三张和第四张床上的霍比特人各一个枕头。

在第二个例子中,弗罗多最多可以拿四个枕头,并给其余每个人三个枕头。

在第三个例子中,弗罗多可以拿三个枕头,给中间位置的霍比特人两个枕头,给第三张床上的霍比特人一个枕头。

输入解题思路,AI测评打分。不知道怎么写?

首页