All problems

Problem 871

Maximum Value at a Given Index in a Bounded Array

Medium · 20 pts · Math, Binary Search, Greedy

Problem

Build an array of N positive integers whose neighbouring elements differ by at most 1 and whose total is at most MAXSUM. Maximise the element at position INDEX (0-based). For a peak value v, the cheapest array decreases by 1 on each side of INDEX until it reaches 1 and then stays at 1; its sum has a closed form, and it grows with v, so binary search on v.

Input

A single line with N, INDEX and MAXSUM.

Output

Print the maximum possible value at INDEX.

Constraints

1 <= N <= MAXSUM <= 10^9; 0 <= INDEX < N

Example input

4 2 6

Example output

2

Explanation

With N = 4, INDEX = 2 and MAXSUM = 6, the array 1 2 2 1 has sum 6 and value 2 at index 2. A value of 3 would need at least 2 + 3 + 2 + 1 = 8, so the answer is 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Fair Candy Swap Next: Minimum Limit of Balls in a Bag