#P9979. [USACO23DEC] Target Practice S
[USACO23DEC] Target Practice S
Problem Description
Bessie is a bionic cow. On a number line, she is trying to hit () targets at distinct positions. Bessie starts at position and follows a command sequence of length (), consisting of L, F, and R:
L: Bessie moves one unit to the left.R: Bessie moves one unit to the right.F: Bessie shoots. If there is a target at Bessie's current position, that target is hit and destroyed. It cannot be hit again.
If, before Bessie starts, you are allowed to change at most one command in the sequence, what is the maximum number of targets Bessie can hit?
Input Format
The first line contains and .
The next line contains the positions of the targets, all distinct integers in the range .
The next line contains a command sequence of length , containing only the characters F, L, and R.
Output Format
Output the maximum number of targets Bessie can hit after changing at most one command.
3 7
0 -1 1
LFFRFRR
3
1 5
0
FFFFF
1
5 6
1 2 3 4 5
FFRFRF
3
Hint
Sample Explanation 1
If you do not make any changes to the command sequence, Bessie will hit two targets.
| Command | Position | Number of Targets Hit |
|---|---|---|
| Start | 0 | 0 |
| L | -1 | |
| F | 1 | |
| 1 (a target cannot be destroyed more than once) | ||
| R | 0 | 1 |
| F | 2 | |
| R | 1 | |
| 2 |
If you change the last command from R to F, Bessie will hit three targets:
| Command | Position | Number of Targets Hit |
|---|---|---|
| Start | 0 | 0 |
| L | -1 | |
| F | 1 | |
| 1 (a target cannot be destroyed more than once) | ||
| R | 0 | 1 |
| F | 2 | |
| R | 1 | |
| F | 3 |
Sample Explanation 2
If the command sequence is not modified, the only target at position will be hit.
Since a target cannot be destroyed multiple times, the answer is .
Test Point Properties
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5