whatever point a robot arrives at a divider, it pivots right away and proceeds with his ride the other way with a similar speed.    At whatever point a few robots meet at a similar integer organize, they impact and detonate into dust. When a robot has detonated, it doesn't slam into some other robot. Note that if a few robots meet at a non

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter19: Probabilistic Dynamic Programming
Section19.4: Further Examples Of Probabilistic Dynamic Programming Formulations
Problem 7P
icon
Related questions
Question

Correct answer will be upvoted else downvoted. Computer science.

 

At whatever point a robot arrives at a divider, it pivots right away and proceeds with his ride the other way with a similar speed. 

 

At whatever point a few robots meet at a similar integer organize, they impact and detonate into dust. When a robot has detonated, it doesn't slam into some other robot. Note that if a few robots meet at a non-integer facilitate, nothing occurs. 

 

For every robot see whether it at any point detonates and print the hour of blast on the off chance that it occurs and −1 in any case. 

 

Input 

 

The primary line contains a solitary integer t (1≤t≤1000) — the number of testcases. 

 

Then, at that point, the depictions of t testcases follow. 

 

The primary line of each testcase contains two integers n and m (1≤n≤3⋅105; 2≤m≤108) — the number of robots and the organize of the right divider. 

 

The second line of each testcase contains n integers x1,x2,… ,xn (0<xi<m) — the beginning directions of the robots. 

 

The third line of each testcase contains n space-isolated characters 'L' or 'R' — the beginning headings of the robots ('L' represents left and 'R' represents right). 

 

All directions xi in the testcase are unmistakable. 

 

The amount of n over all testcases doesn't surpass 3⋅105. 

 

Output 

 

For each testcase print n integers — for the I-th robot output the time it detonates at on the off chance that it does and −1 in any case.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr