#P8611. Ant Infection on a Stick
Ant Infection on a Stick
Ant Infection on a Stick
A thin stick of length \(100\) centimeters has \(n\) ants placed on it. Each ant is located at a certain point on the stick and is initially facing either left or right.
Every ant moves at a constant speed of \(1\) cm/s in the direction it is facing. An ant will continue moving until it falls off the stick (i.e. its position becomes \(\le 0\) or \(\ge 100\)). When two ants collide, they immediately reverse their directions.
Among these \(n\) ants, exactly one ant is infected. Furthermore, whenever an infected ant meets (collides with) a healthy ant, the infection is passed on so that both ants become infected. Note that infection can spread indirectly through a chain of collisions.
Your task is to compute the total number of ants that are infected by the time all ants have fallen off the stick.
inputFormat
The first line contains two integers \(n\) and \(k\) (\(1 \le n \le 1000\) and \(1 \le k \le n\)), where \(n\) is the number of ants and \(k\) is the 1-indexed identifier of the initially infected ant.
Each of the next \(n\) lines contains a real number and a character. The real number represents the ant's initial position \(x\) (with \(0 < x < 100\)) and the character is either L
or R
, indicating whether the ant is initially facing left or right. The ants may be given in arbitrary order.
outputFormat
Output a single integer indicating the total number of ants that become infected.
sample
3 2
10 R
50 L
80 L
2
</p>