#K32977. Longest Non-decreasing Segment After Removals

    ID: 24985 Type: Default 1000ms 256MiB

Longest Non-decreasing Segment After Removals

Longest Non-decreasing Segment After Removals

You are given n trees in a row, where each tree has an energy level given by an integer. Then, you are provided with m removal operations, each specifying the 1-indexed position of a tree to remove. After each removal, you need to determine the length of the longest contiguous segment of the remaining trees such that the energy levels are non-decreasing.

More formally, after performing each removal operation in order, compute the maximum length of a contiguous subarray of the remaining sequence that is non-decreasing. If m is 0, then there is no removal and no output is produced.

Note: The removals persist. That is, once a tree is removed, it is no longer considered in the sequence for subsequent removals.

Input/Output Format: You will read input from standard input (stdin) and output your answer to standard output (stdout).

Example:

Input:
5
1 2 2 3 5
2
2 3

Output:
4 3

inputFormat

The first line contains an integer n (the number of trees). The second line contains n integers representing the energy levels of the trees. The third line contains an integer m (the number of removals). The fourth line contains m space-separated integers representing the positions (1-indexed) of the trees to be removed, in the order they are removed.

outputFormat

Output m integers separated by a single space, where the i-th integer represents the length of the longest contiguous non-decreasing segment after the i-th removal. If m is 0, output nothing.

## sample
5
1 2 2 3 5
0