cswork / OAOpen practice workspace

AmazonOA #129

Create Array Generator Service

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsGreedySimulation

At each step, pick any currently available element (repeats allowed) and append it to the result; then every position that is 0 and whose left neighbor was originally 1 becomes 1 simultaneously. Unlocking does not depend on what was picked and spreads only one cell to the right. Perform m steps and maximize the result lexicographically. When everything is 0 and nothing can be picked, this site's standard I/O convention is to output -1.

Input

The first line contains n m, the second line contains n positive integers, and the third line contains a 01 availability string. This site sets 1≤n,m≤100000, elements in 1..10⁹, and a string length of n.

Output

If there is no solution, output -1; otherwise output the m chosen values.

Example 1

Input:

4 2
10 5 7 6
0101

Output:

6 7

Example 2

Input:

5 4
4 9 1 2 10
10010

Output:

4 10 10 10

Example 3

Input:

2 3
2 9
00

Output:

-1

Example notes

Example 1: initially 5 and 6 are available, so take 6 first; after 7 is unlocked, take 7. Example 2: take 4 first; after one round both 9 and 10 are unlocked, and every later pick is 10, so output 4 10 10 10, correcting the source's 4 9 10 10. Example 3: no element is initially available, so there is no solution; output -1.

Editorial

Loading solution…