#SGM0000074. Tấm biển trên hàng rào (Sign on Fence)
Tấm biển trên hàng rào (Sign on Fence)
Sign on Fence
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem
Panel has height . For query , choose exactly consecutive panels inside . A rectangular sign can be as high as the minimum panel in that chosen block. Maximize this height.
Input
The first line contains , then the heights, then , followed by queries .
Output
Print the maximum possible sign height for every query.
Subtasks
Subtask 1 (20%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- , number of queries .
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
Example
Input
5
1 2 2 3 3
3
2 5 3
2 5 2
1 5 5
Output
2
3
1
Explanation
For 2 5 3, panels 2..4 have heights [2,2,3], so a height- sign fits.