Exhibition 3
시간 제한3초메모리 제한2048 MB
주어진 구간들의 구간 최댓값 수열이 사전순으로 최대가 되도록 배열을 재배치하고, 그때의 각 구간 최댓값을 구한다.
문제
The JOI Art Museum is planning to hold an exhibition of paintings soon. The museum owns paintings numbered from to , and the beauty of painting () is given as . For the exhibition, these paintings will be arranged in a single row from left to right, but the order in which they are placed has not yet been determined.
There will be magazines covering the exhibition. These magazines are numbered from to in descending order of their influence. Each magazine will publish photographs of a certain contiguous segment of paintings in the arranged row. Specifically, magazine () will publish photographs of the -th paintings from the left in the row. The appeal of the article by magazine () is defined as the maximum beauty among the paintings it covers.
JOI-kun, the director of the JOI Art Museum, aims to arrange the paintings in a way that allows these magazines to write articles with greater appeal, thereby attracting more people to the exhibition. Since magazines with greater influence reach a larger audience, he wants to prioritize increasing the appeal of articles in more influential magazines. More precisely, let be the appeal of the article published by magazine (), then JOI-kun wants to arrange the paintings so that the sequence is lexicographically maximized. Here, for two distinct sequences and , is said to be lexicographically larger than when, for the smallest index () such that , holds.
Write a program which, given the information of the paintings to be exhibited and the magazines covering the event, calculates the appeal of each magazine’s article when the paintings are arranged to maximize the lexicographical order of sequence .
입력
Read the following data from the standard input.
출력
Write lines to the standard output. The -th line () of the output should contain , the appeal of the article published by magazine . Here, the sequence must be lexicographically maximized.
제한
- .
- .
- ().
- ().
- Given values are all integers.