#P9974. Candy Bar Feeding Simulation

    ID: 23118 Type: Default 1000ms 256MiB

Candy Bar Feeding Simulation

Candy Bar Feeding Simulation

Farmer John has N cows and M candy bars. Each cow has an initial height and each candy bar has a distinct length. The candy bars are hung sequentially in the order given in the input. For each candy bar, the cows line up in order. When a cow comes to a candy bar, it can eat a portion from the bottom of the candy bar, but at most the segment up to its current height. More formally, if the candy bar has a total length \(L\) and an amount \(E\) has already been eaten from the bottom, then the cow with current height \(h\) will eat \(\min(h - E, L - E)\) units (if \(h > E\)); otherwise, it eats nothing. After its turn, the cow’s height increases by the amount it just ate. Note that even when part of the candy bar is eaten from the bottom, the candy bar remains suspended at its original position. This process is repeated for every candy bar. The task is to determine the final heights of all cows after all candy bars have been processed.

inputFormat

The first line contains two integers N and M (1 \(\le\) N, M \(\le\) 2\(\cdot\)105). The second line contains N integers, representing the initial heights of the cows. The third line contains M integers, representing the lengths of the candy bars in the order they will be hung.

outputFormat

Output a single line with N integers representing the final heights of the cows after all candy bars have been processed, in the same order as input.

sample

3 2
2 1 3
3 2
6 1 4