Target Practice
Time limit2sMemory limit1024 MB
Given targets on a number line and a string of L, R, and F commands, find the most targets Bessie can hit after changing at most one command.
- Level
Medium6 of 10
- Topics
- Simulation, Prefix sum, Array
- Solved
- No attempts yet
Problem
Bessie is a robovine, also known as a cowborg. She is on a number line trying to shoot a series of targets located at distinct positions. Bessie starts at position and follows a string of commands, each one of L, F, or R.
- L: Bessie moves one unit to the left.
- R: Bessie moves one unit to the right.
- F: Bessie fires. If there is a target at Bessie's current position, it is hit and destroyed, and cannot be hit again.
If you may change up to one command in the string to a different command before Bessie starts following it, what is the maximum number of targets that Bessie can hit?
Input
The first line contains and .
The next line contains the locations of the targets, distinct integers in the range .
The last line contains the command string of length , containing only the characters F, L, and R.
Output
Print the maximum number of targets that Bessie can hit after changing up to one command in the string.