[Solution] Ela Takes Dancing Class Codeforces Solution
students in the dancing class, including Ela. In the final project, students will participate in a choreography described below.
students are positioned on the positive side of the -axis. The -th dancer is located at . Some dancers will change positions during the dance (we'll call them movable dancers), and others will stay in the same place during a choreography (we'll call them immovable dancers). We distinguish the dancers using a binary string of length : if equals '1', then the -th dancer is movable, otherwise the -th dancer is immovable.
Let's call the "positive energy value" of the choreography . The dancers will perform "movements" based on this value.
Each minute after the dance begins, the movable dancer with the smallest -coordinate will start moving to the right and initiate a "movement". At the beginning of the movement, the dancer's energy level will be initiated equally to the positive energy value of the choreography, which is . Each time they move from some to , the energy level will be decreased by . At some point, the dancer might meet other fellow dancers in the same coordinates. If it happens, then the energy level of the dancer will be increased by . A dancer will stop moving to the right when his energy level reaches , and he doesn't share a position with another dancer.
The dancers are very well-trained, and each "movement" will end before the next minute begins.
To show her understanding of this choreography, Ela has to answer queries, each consisting of two integers and . The answer to this query is the coordinate of the -th dancer of both types from the left at -th minute after the choreography begins. In other words, denote as the sorted coordinates of the dancers at -th minute from the beginning, you need to print .
The first line contains three integers , and (; ; ) — the number of dancers, the positive energy value of the choreography, and the number of queries.
The second line contains integers () — the coordinates of each dancer.
The third line contains a binary string of length — the movability of each dancer. Each character is either '0' or '1'. It is guaranteed that contains at least one character '1'.
Then lines follow, the -th of them contains two integers and (, ) — the content of each query.
Output lines, each contains a single integer — the answer for the corresponding query.
No comments:
Post a Comment