#DSU0000077. Mike và chiều cao của những chú gấu (Mike and Feet)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mike và chiều cao của những chú gấu (Mike and Feet)
Mike and Feet
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are bears standing in a row, with height for bear . A group is any non-empty contiguous subarray of bears. Its size is the number of bears, and its strength is the minimum bear height in the group.
For each group size , determine the maximum possible strength among all contiguous groups of exactly bears.
A segment of length contains exactly consecutive bears. Its strength is the minimum of their heights; even a single short bear may reduce the strength of the entire segment.
A different segment may be chosen for each . The goal is to maximize the minimum height among segments of exactly elements, not segments of length at least or at most .
Input
The first line contains ; the second contains .
Output
Print integers; integer is the maximum strength of a subarray of length .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
10
1 2 3 4 5 4 3 2 1 6
Output
6 4 4 3 3 2 2 1 1 1
Explanation
For , the tallest bear gives strength . For lengths and , the maximum attainable minimum height is . For each remaining length, compare all segments of exactly that length and take the largest minimum height.