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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 positive integers whose adjacent values differ by at most 1 and whose sum is at most . Find the largest possible value of , where is zero-based.
Input
One line contains three integers .
Output
Print the largest achievable value at index p.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; or .
- Subtask 3 (50 points): ; .
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.