atcoder#ARC098C. [ARC098E] Range Minimum Queries
[ARC098E] Range Minimum Queries
Score : points
Problem Statement
You are given an integer sequence of length and an integer . You will perform the following operation on this sequence times:
- Choose a contiguous subsequence of length , then remove the smallest element among the elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).
Let and be the values of the largest and smallest element removed in the operations. You would like to be as small as possible. Find the smallest possible value of when the operations are performed optimally.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the smallest possible value of .
5 3 2
4 3 1 5 2
1
In the first operation, whichever contiguous subsequence of length we choose, the minimum element in it is . Thus, the first operation removes and now we have . In the second operation, it is optimal to choose as the contiguous subsequence of length and remove . In this case, the largest element removed is , and the smallest is , so their difference is .
10 1 6
1 1 2 3 5 8 13 21 34 55
7
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
451211184