Guess the Random Number
InterviewTime limit1sMemory limit1024 MB
Given member weights and the winners in draw order, print a ticket index for each draw that makes that member win, using the remaining tickets.
- Level
Medium4 of 10
- Topics
- Prefix sum, Array
- Solved
- No attempts yet
Problem
A lottery at Youngkwa Day awards prizes to members who solved many problems during one semester.
Each member gets a weight that raises their chance of winning. If a member solved problems, their weight is .
There are members who solved at least one problem this semester. They are numbered from to .
The lottery picks winners out of the members. It starts with and runs as follows.
- Going through members to in order, add each member's ticket to the list as many times as their weight. For example, if there are 3 members with weights , then . ( is the ticket of member .)
- Pick one integer from to at random and call it .
- Select the -th ticket from the front of to pick one winner.
- Remove all tickets of the member who just won from .
- If , increase by and go back to step 2. Otherwise, end the lottery.
The winners' numbers are given in the order they were drawn. Guess which random numbers were drawn, in order.
Input
The first line contains and , separated by a space.
The second line contains the weight of each member, separated by spaces. There are values.
The third line contains the member numbers of the winners, in the order they were drawn, separated by spaces. There are values.
All input values are integers.
Output
Print the sequence of random numbers drawn during the lottery, separated by spaces.
If more than one sequence is possible, print any one of them.