KVALTWR - Bob and his towers

no tags 

Bytie has got a set of wooden blocks for his birthday. The blocks are indistinguishable from one another, as they are all cubes of the same size. Bytie forms piles by putting one block atop another. Soon he had a whole rank of such piles, one next to another in a straight line. Of course, the piles can have different heights.

Bytie's father, Byteasar, gave his son a puzzle. He gave him a number k and asked to rearrange the blocks in such a way that the number of successive piles of height at least k is maximised. However, Bytie is only ever allowed to pick the top block from a pile strictly higher than k and place it atop one of the piles next to it. Further, Bytie is not allowed to form new piles, he can only move blocks between those already existing.

Input

In the first line of the standard input there are two integers separated by a single space: n (1 ≤ n ≤ 1,000,000), denoting the number of piles, and m (1 ≤ m ≤ 50), denoting the number of Byteasar's requests. The piles are numbered from 1 to n. In the second line there are n integers x1,x2,…,xn separated by single spaces (1 ≤ xi ≤ 1,000,000,000). The number xi denotes the height of the i-th pile. The third line holds m integers k1,k2,…,km separated by single spaces (1 ≤ ki ≤ 1,000,000,000). These are the subsequent values of the parameter k for which the puzzle is to be solved. That is, the largest number of successive piles of height at least k that can be obtained by allowed moves is to be determined for each given value of the parameter k.

Output

Your program should print out m integers, separated by single spaces, to the standard output - the i-th of which should be the answer to the puzzle for the given initial piles set-up and the parameter ki.

Example

For the input data:

5 6
1 2 1 1 5
1 2 3 4 5 6

the correct result is:

5 5 2 1 1 0


hide comments
hello_1234: 2021-03-27 13:34:13

what would be the output.
should i print "the correct result is: "

[Rampage] Blue.Mary: 2012-06-26 21:16:01

O(NlogN * M) can pass, but... Be careful with the constant factors in the program.

Satyarth Kumar Prasad: 2012-06-26 21:16:01

Please provide output data for the example.


Added by:Krzysztof Lewko
Date:2011-06-14
Time limit:0.100s-2.461s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:XVII POI