PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000301. Giá trị lớn nhất tại vị trí chỉ định (Maximum Value at a Given Index in a Bounded Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Giá trị lớn nhất tại vị trí chỉ định (Maximum Value at a Given Index in a Bounded Array)

Maximum Value at a Given Index in a Bounded Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Construct a sequence of nn positive integers a0,…,an−1a_0,\ldots,a_{n-1} whose adjacent values differ by at most 1 and whose sum is at most SS. Find the largest possible value of apa_p, where pp is zero-based.

Input

One line contains three integers n,p,Sn,p,S.

Output

Print the largest achievable value at index p.

Subtasks

  • Subtask 1 (20 points): 1≤n≤S≤1001\le n\le S\le100; 0≤p<n0\le p<n.
  • Subtask 2 (30 points): 1≤n≤S≤1091\le n\le S\le10^9; p=0p=0 or p=n−1p=n-1.
  • Subtask 3 (50 points): 1≤n≤S≤1091\le n\le S\le10^9; 0≤p<n0\le p<n.

Examples

Input 1

4 2 6

Output 1

2

Explanation

The sequence (1,2,2,1) has sum 6. A peak of 3 requires at least (1,2,3,2), sum 8.